diff options
author | danielsdeleo <dan@opscode.com> | 2013-04-18 12:02:33 -0700 |
---|---|---|
committer | danielsdeleo <dan@opscode.com> | 2013-04-18 12:02:33 -0700 |
commit | b7163d13fe84d1b4c45beaef3084f82dc07df415 (patch) | |
tree | 8aa0b402df2890b79967f1d479719346e5a8b7f8 | |
parent | a210f1151d7d51d2ef0b6653e1f463b22dde9a10 (diff) | |
download | chef-b7163d13fe84d1b4c45beaef3084f82dc07df415.tar.gz |
[CHEF-3432] use shared variable to track resource subclasses
Use a class (@@var) instead of class instance variable to track
subclasses of Chef::Resource. This ensures that subclasses of subclasses
will be added to the list.
-rw-r--r-- | lib/chef/resource.rb | 2 | ||||
-rw-r--r-- | spec/unit/resource_spec.rb | 15 |
2 files changed, 16 insertions, 1 deletions
diff --git a/lib/chef/resource.rb b/lib/chef/resource.rb index 729632a69c..5b3a3f49b3 100644 --- a/lib/chef/resource.rb +++ b/lib/chef/resource.rb @@ -132,7 +132,7 @@ F # Track all subclasses of Resource. This is used so names can be looked up # when attempting to deserialize from JSON. (See: json_compat) def self.resource_classes - @resource_classes ||= [] + @@resource_classes ||= [] end # Callback when subclass is defined. Adds subclass to list of subclasses. diff --git a/spec/unit/resource_spec.rb b/spec/unit/resource_spec.rb index ffcc7ae5b4..964946a339 100644 --- a/spec/unit/resource_spec.rb +++ b/spec/unit/resource_spec.rb @@ -35,6 +35,21 @@ describe Chef::Resource do @resource = Chef::Resource.new("funk", @run_context) end + describe "when inherited", :focus do + + it "adds an entry to a list of subclasses" do + subclass = Class.new(Chef::Resource) + Chef::Resource.resource_classes.should include(subclass) + end + + it "keeps track of subclasses of subclasses" do + subclass = Class.new(Chef::Resource) + subclass_of_subclass = Class.new(subclass) + Chef::Resource.resource_classes.should include(subclass_of_subclass) + end + + end + describe "when declaring the identity attribute" do it "has no identity attribute by default" do Chef::Resource.identity_attr.should be_nil |