I'm trying to write an RSpec helper for testing cached actions:


How it works is visible in lib/rspec-rails-caching.rb, but to outline the
setup process:

1. Define the global RAILS_CACHE constant (i.e. Rails.cache) to a
CacheStore object that handles recording.
2. Turn on perform_caching which is normally false in the test environment.
3. Reload the described controller.

Reloading the controller class is necessary because the cache callbacks
(after process_action) are metaprogrammed into the class, and they don't
get added when the class is loaded while
ActionController::Base.perform_caching is false. (These are the numbered
methods that look like WidgetsController#_callback_after_2961)

This helper seems to be mostly working. By "mostly" I mean my spec will
pass/fail correctly based on the expectations when I run individual
examples INSIDE my caching block. The problem is that if I run the whole
spec file with examples that are OUTSIDE my caching block too, then the
controller's caching callbacks don't get triggered. I've stepped through
process_action in the debugger and I can't figure out what is the
difference between the two scenarios. I've confirmed that both have:

1. perform_caching is true
2. The cache_store is my TestStore object
2. The _callback_after_2961 metaprogrammed caching method is defined on the
controller class
3. The callback method shows up in the _process_action_callbacks chain

Still, there seems to be some difference whether the class is first loaded
inside or outside the caching example group. How can I force the class to
reload "cleanly" to ensure the caching callbacks get run? Or is there a
better solution?

You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/kew0twnD2ywJ.
For more options, visit https://groups.google.com/groups/opt_out.

Search Discussions

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
postedNov 27, '12 at 10:42p
activeNov 27, '12 at 10:42p

1 user in discussion

Andrew Vit: 1 post



site design / logo © 2022 Grokbase