Generally, I want my functional tests to not perform action caching. Rails seems to be on my side, defaulting to config.action_controller.perform_caching = false in environment/test.rb. This leads to normal functional tests not testing the caching.
So how do I test caching in Rails 3.
The solutions proposed in this thread seem rather hacky or taylored towards Rails 2:
How to enable page caching in a functional test in rails?
I want to do something like:
test "caching of index method" do
with_caching do
get :index
assert_template 'index'
get :index
assert_template ''
end
end
Maybe there is also a better way of testing that the cache was hit?
You’re liable to end up with tests stomping on each other. You should wrap this up with ensure and reset it to old values appropriately. An example:
I’ve also put this into a module so you can just include this in your test class or parent class.