summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Keiser <john@johnkeiser.com>2015-09-29 16:06:41 -0700
committerJohn Keiser <john@johnkeiser.com>2015-09-29 18:27:46 -0700
commitd1a0e4b9dc4b5f00ce7fa5d56866fa0cbe8413e9 (patch)
tree551a2fd1bce54daad84e3d248b571a38a1d554f0
parentd0d9e5b7a6973fbb250b9344038c2e79deb28599 (diff)
downloadchef-d1a0e4b9dc4b5f00ce7fa5d56866fa0cbe8413e9.tar.gz
Add ability for default to override name_propertyjk/name-default
-rw-r--r--lib/chef/property.rb11
-rw-r--r--spec/unit/property_spec.rb12
2 files changed, 19 insertions, 4 deletions
diff --git a/lib/chef/property.rb b/lib/chef/property.rb
index b8d8005655..c1207d9132 100644
--- a/lib/chef/property.rb
+++ b/lib/chef/property.rb
@@ -422,11 +422,14 @@ class Chef
# @return [Property] The new property type.
#
def derive(**modified_options)
- # Since name_property and name_attribute are aliases, if you specify either
- # one in modified_options it overrides anything in original options.
+ # Since name_property, name_attribute and default override each other,
+ # if you specify one of them in modified_options it overrides anything in
+ # the original options.
options = self.options
- if modified_options.has_key?(:name_property) || modified_options.has_key?(:name_attribute)
- options = options.reject { |k,v| k == :name_attribute || k == :name_property }
+ if modified_options.has_key?(:name_property) ||
+ modified_options.has_key?(:name_attribute) ||
+ modified_options.has_key?(:default)
+ options = options.reject { |k,v| k == :name_attribute || k == :name_property || k == :default }
end
Property.new(options.merge(modified_options))
end
diff --git a/spec/unit/property_spec.rb b/spec/unit/property_spec.rb
index 456da89dcf..9ecf7a4cde 100644
--- a/spec/unit/property_spec.rb
+++ b/spec/unit/property_spec.rb
@@ -142,6 +142,18 @@ describe "Chef::Resource.property" do
expect(subresource.x).to be_nil
end
end
+
+ context "with property :x, default: 10 on the subclass" do
+ before do
+ subresource_class.class_eval do
+ property :x, default: 10
+ end
+ end
+
+ it "x is no longer name_property" do
+ expect(subresource.x).to eq(10)
+ end
+ end
end
end