I want to test my caching behavior, and something along these lines fails:
context "without cache" do
it "should return the appropriate result, computing it every time", :caching => false do
p ActionController::Base.perform_caching
Object.should_receive(:where).exactly(4).and_call_original
result1 = SomeService.action(args1, args2)
result2 = SomeService.action(args1, args2)
end
end
...even though false
is printed out for the ActionController::Base.perform_caching
. [This is disabled by the :caching => false
option of the bloc (I use a hook)]
If I totally shut down caching by switching from the default :memory_store
to the :null_store
for the testing environment, the test passes as expected. I just add this line in test.rb
:
config.cache_store = :null_store
My action
method uses the core caching from Rails:
def action(args1, args2):
...
objects = Rails.cache.fetch(cache_key, expires_in: 5.days) do
object.where(id: args1).where(charac: args2).includes(...).to_a
end
...
end
As a matter of fact,
ActionController::Base.perform_caching
nor its counterpartconfig.action_controller.perform_caching
is meant to control low level caching.I submitted an issue+PR to change the docs that can be very misleading.