Rails 3 functional optionally testing caching

Posted by Stephan on Stack Overflow See other posts from Stack Overflow or by Stephan
Published on 2011-02-17T23:23:26Z Indexed on 2011/02/17 23:25 UTC
Read the original article Hit count: 330

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?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby-on-rails-3