Skip to content

Commit

Permalink
[CHEF-3432] use shared variable to track resource subclasses
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
danielsdeleo committed Apr 18, 2013
1 parent a210f11 commit b7163d1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/chef/resource.rb
Expand Up @@ -132,7 +132,7 @@ def fix_notifier_reference(resource_collection)
# 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.
Expand Down
15 changes: 15 additions & 0 deletions spec/unit/resource_spec.rb
Expand Up @@ -35,6 +35,21 @@ class ResourceTestHarness < Chef::Resource
@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
Expand Down

0 comments on commit b7163d1

Please sign in to comment.