|
4 | 4 | require 'rspec-rails-caching/extensions/action_controller'
|
5 | 5 |
|
6 | 6 | module RSpecRailsCaching
|
7 |
| - RSpec::Rails::ControllerExampleGroup.class_eval do |
8 |
| - include Matchers |
9 |
| - end |
10 | 7 |
|
11 | 8 | RSpec.configure do |config|
|
12 |
| - config.before(:all, :type => :controller, :caching => true) do |example| |
| 9 | + if ActionController::Base.perform_caching |
13 | 10 | silence_warnings do
|
14 |
| - @_orig_cache_store = RAILS_CACHE |
15 |
| - Object.const_set "RAILS_CACHE", TestStore.new |
| 11 | + Object.const_set :RAILS_CACHE, TestStore.new(true) |
16 | 12 | end
|
17 |
| - |
18 | 13 | ActionController::Base.cache_store = RAILS_CACHE
|
19 |
| - ActionController::Base.perform_caching = true |
| 14 | + ActionController::Base.class_eval do |
| 15 | + extend Extensions::ActionController::ClassMethods |
| 16 | + end |
20 | 17 |
|
21 |
| - # The controller needs to be reloaded to metaprogram the caches_page |
22 |
| - # callback with the perform_caching option turned on. There is no |
23 |
| - # reloading if the example controller isn't in the load paths, likely |
24 |
| - # because it was defined inline in the spec or an AnonymousController. |
25 |
| - if ctrl_class_file = |
26 |
| - ActiveSupport::Dependencies.search_for_file(example.class.controller_class.to_s.underscore) |
27 |
| - then |
28 |
| - # FIXME: the controller's cache_page callbacks don't get triggered |
29 |
| - # when the test suite runs an outer example group (without caching: |
30 |
| - # true), but individual examples will pass. |
31 |
| - ActiveSupport::Dependencies.load(ctrl_class_file) |
| 18 | + RSpec::Rails::ControllerExampleGroup.class_eval do |
| 19 | + include Matchers |
32 | 20 | end
|
33 | 21 |
|
34 |
| - example.class.controller_class.class_eval do |
35 |
| - self.perform_caching = true |
36 |
| - extend Extensions::ActionController::ClassMethods |
| 22 | + config.before :each do |example| |
| 23 | + RAILS_CACHE.reset |
37 | 24 | end
|
38 |
| - end |
39 | 25 |
|
40 |
| - config.after(:all, :type => :controller, :caching => true) do |example| |
41 |
| - silence_warnings do |
42 |
| - Object.const_set "RAILS_CACHE", @_orig_cache_store |
| 26 | + config.after :each do |example| |
| 27 | + RAILS_CACHE.reset |
43 | 28 | end
|
44 |
| - ActionController::Base.cache_store = RAILS_CACHE |
45 |
| - ActionController::Base.perform_caching = false |
46 | 29 | end
|
47 | 30 | end
|
48 | 31 |
|
|
0 commit comments