Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix inheritability of cached resource configuration

Signed-off-by: David Souza <david@souza.net>
  • Loading branch information...
commit b3f363e06674a2d8872cbd5ad0e1b0cc45bd8f2c 1 parent 35bf90d
Morgan Brown authored davidsouza committed
View
10 lib/cached_resource/cached_resource.rb
@@ -24,5 +24,15 @@ def setup_cached_resource!(options)
end
end
+ module ClassMethods
+ # Copy a superclass's cached resource configuration if
+ # it's defined. Unfortunately, this means that any subclass
+ # that wants an independent configuration will need to execute:
+ # self.cached_resource = CachedResource::Configuration.new(options={})
+ def inherited(child)
+ child.cached_resource = self.cached_resource if defined?(@cached_resource)
+ end
+ end
+
end
end
View
28 spec/cached_resource/configuration_spec.rb
@@ -124,4 +124,32 @@ class Bar < ActiveResource::Base
end
+ describe "when cached resource is inherited" do
+ before(:each) do
+ class Bar < ActiveResource::Base
+ cached_resource :ttl => 1,
+ :cache => "cache",
+ :logger => "logger",
+ :enabled => false,
+ :collection_synchronize => true,
+ :collection_arguments => [:every],
+ :custom => "irrelevant"
+ end
+
+ class Foo < Bar
+ cached_resource
+ end
+ end
+
+ after(:each) do
+ Object.send(:remove_const, :Foo)
+ Object.send(:remove_const, :Bar)
+ end
+
+ it "it should make sure each subclass has the same configuration" do
+ Bar.cached_resource.object_id.should == Foo.cached_resource.object_id
+ end
+
+ end
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.