Optionally testing caching in Rails 3 functional tests -
generally, want functional tests not perform action caching. rails seems on side, defaulting config.action_controller.perform_caching = false
in environment/test.rb
. leads normal functional tests not testing caching.
so how test caching in rails 3.
the solutions proposed in thread seem rather hacky or taylored towards rails 2: how enable page caching in functional test in rails?
i want like:
test "caching of index method" with_caching :index assert_template 'index' :index assert_template '' end end
maybe there better way of testing cache hit?
you're liable end tests stomping on each other. should wrap ensure , reset old values appropriately. example:
module actioncontroller::testing::caching def with_caching(on = true) caching = actioncontroller::base.perform_caching actioncontroller::base.perform_caching = on yield ensure actioncontroller::base.perform_caching = caching end def without_caching(&block) with_caching(false, &block) end end
i've put module can include in test class or parent class.
Comments
Post a Comment