diff options
author | John Keiser <john@johnkeiser.com> | 2015-09-22 22:15:19 -0700 |
---|---|---|
committer | John Keiser <john@johnkeiser.com> | 2015-09-22 22:50:28 -0700 |
commit | d8f7ca4d08f00db96fbf1e98a7f1ed763c7bab01 (patch) | |
tree | 73cec404209729267202b0e28ba888d84fc1046a | |
parent | 0d93133c31704711b2bb6a20db74a83dc1b23493 (diff) | |
download | chef-d8f7ca4d08f00db96fbf1e98a7f1ed763c7bab01.tar.gz |
Honor the ordering of whichever `name_attribute` or `default` comes first
-rw-r--r-- | lib/chef/property.rb | 15 | ||||
-rw-r--r-- | spec/unit/property_spec.rb | 4 |
2 files changed, 17 insertions, 2 deletions
diff --git a/lib/chef/property.rb b/lib/chef/property.rb index 09198d90f1..5b6a969d5f 100644 --- a/lib/chef/property.rb +++ b/lib/chef/property.rb @@ -86,6 +86,21 @@ class Chef # def initialize(**options) options.each { |k,v| options[k.to_sym] = v if k.is_a?(String) } + # Only pick the first of :default, :name_property and :name_attribute if + # more than one is specified. + found_default = false + options.reject! do |k,v| + if [ :name_property, :name_attribute, :default ].include?(k) + if found_default + true + else + found_default = true + false + end + else + false + end + end options[:name_property] = options.delete(:name_attribute) if options.has_key?(:name_attribute) && !options.has_key?(:name_property) @options = options diff --git a/spec/unit/property_spec.rb b/spec/unit/property_spec.rb index f758b5f403..533f0f4e4d 100644 --- a/spec/unit/property_spec.rb +++ b/spec/unit/property_spec.rb @@ -952,8 +952,8 @@ describe "Chef::Resource.property" do end end with_property ":x, #{name}: true, default: 10" do - it "chooses default over #{name}" do - expect(resource.x).to eq 10 + it "chooses #{name} over default" do + expect(resource.x).to eq 'blah' end end with_property ":x, #{name}: true, required: true" do |