summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Keiser <john@johnkeiser.com>2016-01-22 14:20:38 -0800
committerJohn Keiser <john@johnkeiser.com>2016-01-22 14:20:38 -0800
commit9b33d77a80db0143db21d132bad0e220c47786b5 (patch)
treedb40eae28b1f1d3895607417a80ef5f83b152e99
parent1cb9cc67b71d21d1207602d1ec50ad2d68486171 (diff)
downloadchef-9b33d77a80db0143db21d132bad0e220c47786b5.tar.gz
Fix #4334: don't warn about ambiguous property usage
unless using properties on the resource
-rw-r--r--lib/chef/property.rb3
-rw-r--r--spec/integration/recipes/resource_action_spec.rb28
2 files changed, 30 insertions, 1 deletions
diff --git a/lib/chef/property.rb b/lib/chef/property.rb
index 8ff4ecc7fc..8b5c6560a9 100644
--- a/lib/chef/property.rb
+++ b/lib/chef/property.rb
@@ -320,7 +320,8 @@ class Chef
resource.resource_initializing &&
resource.respond_to?(:enclosing_provider) &&
resource.enclosing_provider &&
- resource.enclosing_provider.respond_to?(name)
+ resource.enclosing_provider.new_resource &&
+ resource.enclosing_provider.new_resource.respond_to?(name)
Chef::Log.warn("#{Chef::Log.caller_location}: property #{name} is declared in both #{resource} and #{resource.enclosing_provider}. Use new_resource.#{name} instead. At #{Chef::Log.caller_location}")
end
diff --git a/spec/integration/recipes/resource_action_spec.rb b/spec/integration/recipes/resource_action_spec.rb
index b8c533b31d..a0cc346988 100644
--- a/spec/integration/recipes/resource_action_spec.rb
+++ b/spec/integration/recipes/resource_action_spec.rb
@@ -436,6 +436,34 @@ describe "Resource.action" do
end
+ context "With a resource with a set_or_return property named group (same name as a resource)" do
+ class ResourceActionSpecWithGroupAction < Chef::Resource
+ resource_name :resource_action_spec_set_group_to_nil
+ action :set_group_to_nil do
+ # Access x during converge to ensure that we emit no warnings there
+ resource_action_spec_with_group 'hi' do
+ group nil
+ action :nothing
+ end
+ end
+ end
+
+ class ResourceActionSpecWithGroup < Chef::Resource
+ resource_name :resource_action_spec_with_group
+ def group(value=nil)
+ set_or_return(:group, value, {})
+ end
+ end
+
+ it "Setting group to nil in an action does not emit a warning about it being defined in two places" do
+ expect_recipe {
+ resource_action_spec_set_group_to_nil "hi" do
+ action :set_group_to_nil
+ end
+ }.to emit_no_warnings_or_errors
+ end
+ end
+
context "When a resource has a property with the same name as another resource" do
class HasPropertyNamedTemplate < Chef::Resource
use_automatic_resource_name