如何在rails中的function测试中启用页面缓存?
是否可以打开页面缓存进行function测试? 以下不起作用:
class ArticlesControllerTest < ActionController::TestCase def setup ActionController::Base.public_class_method :page_cache_path ActionController::Base.perform_caching = true end end
提前致谢
德布
我目前的解决方法是启用perform_caching
然后重新加载控制器:
class ProjectsCachingTest < ActionController::IntegrationTest def setup # force the controller to be reloaded when caching is enabled ActionController::Base.perform_caching = true load "projects_controller.rb" end def teardown # undo the actions above ActionController::Base.perform_caching = false load "projects_controller.rb" end end
在最新版本的Rails 2中,您遇到的问题与类方法caches_action
和caches_page
。 它们都创建了一个aroundfilter来执行缓存,但只有在启用perform_caching
时才会这样做。
因此,在运行时修改perform_caching
不会重新创建预期的周围filter。 上面的示例是强制重新评估控制器的一种方法。
我无法弄清楚为什么这不起作用,所以我最终直接在environments/test.rb
上启用缓存:
config.action_controller.perform_caching = true