I feel that this is not a very well-documented topic, at least I had problems finding the best practices.
I am caching fragments in a view using cache_key:
%tbody - @employees.each do |employee| - cache employee do %tr[employee] %td= employee.name %td= employee.current_positions %td= employee.home_base %td= employee.job_classes
Now I can add: touch => true on the: belongs_to side of my has_many associations, and this will do everything I need to update this fragment, but for my life I can hardly figure out how to check this.
Dropping: touch => true is easy and convenient, but it extends the expiration logic to a couple of places. I would like to have an RSpec request specification that goes through and checks the behavior on this, which cannot change much, but can bring all the caching requirements into one specific file describing what is going to happen.
I tried the following lines:
require 'spec_helper' include AuthenticationMacros describe "Employee index caching" do before do Rails.cache.clear ActionController::Base.perform_caching = true login_confirmed_employee end after do ActionController::Base.perform_caching = false end specify "the employee cache is cleared when position assignments are modified" specify "the employee cache is cleared when home base assignments are modified" end
The specs focused on Capybara's steps that went through and made updates, of course, and I thought I was on the right track. But the tests flickered in strange ways. I would change the specifications to display employee cache_key objects, and sometimes cache_keys will change, and sometimes not, sometimes specifications will pass, and sometimes not.
Is this even a good approach?
I know that SO wants to answer questions, so for starters: how can I tune and demolish this test to use caching when my test env has no default caching? In general, however, I would love to hear how you can successfully test fragment caching in your applications if you have had success with this.
EDIT
I accept cailinanne's answer as it solves the problem that I specifically ask, but I decided, however, that I do not even recommend integration testing caching if you can get away from it.
Instead of specifying a touch in my association ads, I created an observer specific to my caching needs, which deals with models directly, and I test it in isolation.
I would recommend that testing the browser of the mullite model separately also include a test to check the observed observed modes, otherwise you might drown out too much reality.
The specific answer that led me to this is given here: https://stackoverflow.com/a/212618/