summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThom May <thom@chef.io>2017-03-07 15:42:58 +0000
committerThom May <thom@chef.io>2017-03-07 15:42:58 +0000
commit5ddebc5768dd28f98dc3c646784ca91d3046eab3 (patch)
treea8d9170ae64742062f1fb49a793776782fc12cdc
parent29c39b56764a52945609b0eeb0f6068da6ed0041 (diff)
downloadchef-tm/demagic_properties_2.tar.gz
Be a bit less keen to help propertiestm/demagic_properties_2
This removes all the magic that attempts to allow users to write unsafe properties - ie, ones that set a default but claim to be a name property. This yielded different results depending on ordering. It's better for our users to just suck up fixing this. Closes: #5542 (Part of #3705) Signed-off-by: Thom May <thom@chef.io>
-rw-r--r--lib/chef/property.rb13
-rw-r--r--spec/unit/property_spec.rb75
2 files changed, 14 insertions, 74 deletions
diff --git a/lib/chef/property.rb b/lib/chef/property.rb
index 8fa290251a..ac226bc815 100644
--- a/lib/chef/property.rb
+++ b/lib/chef/property.rb
@@ -106,17 +106,8 @@ class Chef
@options = options
end
- # Only pick the first of :default, :name_property and :name_attribute if
- # more than one is specified.
- if options.has_key?(:default) && options[:name_property]
- if options[:default].nil? || options.keys.index(:name_property) < options.keys.index(:default)
- options.delete(:default)
- preferred_default = :name_property
- else
- options.delete(:name_property)
- preferred_default = :default
- end
- Chef.deprecated(:custom_resource, "Cannot specify both default and name_property together on property #{self}. Only one (#{preferred_default}) will be obeyed. In Chef 13, this will become an error. Please remove one or the other from the property.")
+ if options.has_key?(:default) && options.has_key?(:name_property)
+ raise ArgumentError, "Cannot specify both default and name_property/name_attribute together on property #{self}"
end
# Validate the default early, so the user gets a good error message, and
diff --git a/spec/unit/property_spec.rb b/spec/unit/property_spec.rb
index 50ff3434f6..0e7bf53ec5 100644
--- a/spec/unit/property_spec.rb
+++ b/spec/unit/property_spec.rb
@@ -1019,74 +1019,23 @@ describe "Chef::Resource.property" do
end
context "default ordering deprecation warnings" do
- it "emits a deprecation warning for property :x, default: 10, #{name}: true" do
- expect { resource_class.property :x, :default => 10, name.to_sym => true }.to raise_error Chef::Exceptions::DeprecatedFeatureError,
- /Cannot specify both default and name_property together on property x of resource chef_resource_property_spec_(\d+). Only one \(default\) will be obeyed./
+ it "emits an error for property :x, default: 10, #{name}: true" do
+ expect { resource_class.property :x, :default => 10, name.to_sym => true }.to raise_error Chef::Exceptions::ArgumentError,
+ /Cannot specify both default and name_property\/name_attribute together on property x of resource chef_resource_property_spec_(\d+)/
end
- it "emits a deprecation warning for property :x, default: nil, #{name}: true" do
- expect { resource_class.property :x, :default => nil, name.to_sym => true }.to raise_error Chef::Exceptions::DeprecatedFeatureError,
- /Cannot specify both default and name_property together on property x of resource chef_resource_property_spec_(\d+). Only one \(name_property\) will be obeyed./
+ it "emits an error for property :x, default: nil, #{name}: true" do
+ expect { resource_class.property :x, :default => nil, name.to_sym => true }.to raise_error Chef::Exceptions::ArgumentError,
+ /Cannot specify both default and name_property\/name_attribute together on property x of resource chef_resource_property_spec_(\d+)/
end
- it "emits a deprecation warning for property :x, #{name}: true, default: 10" do
- expect { resource_class.property :x, name.to_sym => true, :default => 10 }.to raise_error Chef::Exceptions::DeprecatedFeatureError,
- /Cannot specify both default and name_property together on property x of resource chef_resource_property_spec_(\d+). Only one \(name_property\) will be obeyed./
+ it "emits an error for property :x, #{name}: true, default: 10" do
+ expect { resource_class.property :x, name.to_sym => true, :default => 10 }.to raise_error Chef::Exceptions::ArgumentError,
+ /Cannot specify both default and name_property\/name_attribute together on property x of resource chef_resource_property_spec_(\d+)/
end
- it "emits a deprecation warning for property :x, #{name}: true, default: nil" do
- expect { resource_class.property :x, name.to_sym => true, :default => nil }.to raise_error Chef::Exceptions::DeprecatedFeatureError,
- /Cannot specify both default and name_property together on property x of resource chef_resource_property_spec_(\d+). Only one \(name_property\) will be obeyed./
+ it "emits an error for property :x, #{name}: true, default: nil" do
+ expect { resource_class.property :x, name.to_sym => true, :default => nil }.to raise_error Chef::Exceptions::ArgumentError,
+ /Cannot specify both default and name_property\/name_attribute together on property x of resource chef_resource_property_spec_(\d+)/
end
end
-
- context "default ordering" do
- before { Chef::Config[:treat_deprecation_warnings_as_errors] = false }
- with_property ":x, default: 10, #{name}: true" do
- it "chooses default over #{name}" do
- expect(resource.x).to eq 10
- end
- end
- with_property ":x, default: nil, #{name}: true" do
- it "chooses #{name} over default" do
- expect(resource.x).to eq "blah"
- end
- end
- with_property ":x, #{name}: true, default: 10" do
- it "chooses #{name} over default" do
- expect(resource.x).to eq "blah"
- end
- end
- with_property ":x, #{name}: true, default: nil" do
- it "chooses #{name} over default" do
- expect(resource.x).to eq "blah"
- end
- end
- end
-
- context "default ordering when #{name} is nil" do
- with_property ":x, #{name}: nil, default: 10" do
- it "chooses default" do
- expect(resource.x).to eq 10
- end
- end
- with_property ":x, default: 10, #{name}: nil" do
- it "chooses default" do
- expect(resource.x).to eq 10
- end
- end
- end
-
- context "default ordering when #{name} is false" do
- with_property ":x, #{name}: false, default: 10" do
- it "chooses default" do
- expect(resource.x).to eq 10
- end
- end
- with_property ":x, default: 10, #{name}: nil" do
- it "chooses default" do
- expect(resource.x).to eq 10
- end
- end
- end
-
end
end