Skip to content

Commit 4d2ee49

Browse files
committed
Rely on host app having enabled perform_caching
Trying to use caching selectively is a fool's errand. The caching metabrogramming breaks all hope of reloading correctly.
1 parent 1736d52 commit 4d2ee49

File tree

3 files changed

+13
-29
lines changed

3 files changed

+13
-29
lines changed

lib/rspec-rails-caching.rb

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,28 @@
44
require 'rspec-rails-caching/extensions/action_controller'
55

66
module RSpecRailsCaching
7-
RSpec::Rails::ControllerExampleGroup.class_eval do
8-
include Matchers
9-
end
107

118
RSpec.configure do |config|
12-
config.before(:all, :type => :controller, :caching => true) do |example|
9+
if ActionController::Base.perform_caching
1310
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)
1612
end
17-
1813
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
2017

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
3220
end
3321

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
3724
end
38-
end
3925

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
4328
end
44-
ActionController::Base.cache_store = RAILS_CACHE
45-
ActionController::Base.perform_caching = false
4629
end
4730
end
4831

lib/rspec-rails-caching/test_store.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def page_expired?(options = {})
6464
private
6565
def test_cache_url(options)
6666
return options if options.is_a?(String)
67-
url_for(options.merge({ :only_path => true, :skip_relative_url_root => true }))
67+
url_for(options.merge(:only_path => true, :skip_relative_url_root => true))
6868
end
6969
end
7070
end

rspec-rails-caching.gemspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Gem::Specification.new do |gem|
1212

1313
gem.add_dependency "rails", ">=3.0.0"
1414
gem.add_dependency "rspec", ">=2.8.0"
15+
gem.add_dependency "rspec-rails", ">=2.10.0"
1516

1617
gem.files = `git ls-files`.split($\)
1718
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})

0 commit comments

Comments
 (0)