summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordanielsdeleo <dan@opscode.com>2013-04-23 14:46:03 -0700
committerdanielsdeleo <dan@opscode.com>2013-04-23 14:48:21 -0700
commitadd188d365d11f7f11b342b797fe289988238429 (patch)
tree6075a8cd8aa0329e446aa778d9848e47f6413c81
parenta6394701470451c2567017c2f2a1f6b08e7512c1 (diff)
downloadchef-add188d365d11f7f11b342b797fe289988238429.tar.gz
Merge branch 'CHEF-4117'
-rw-r--r--lib/chef/resource/lwrp_base.rb2
-rw-r--r--spec/data/lwrp_const_scoping/resources/conflict.rb0
-rw-r--r--spec/unit/lwrp_spec.rb8
3 files changed, 9 insertions, 1 deletions
diff --git a/lib/chef/resource/lwrp_base.rb b/lib/chef/resource/lwrp_base.rb
index 370ccd8c10..5776bb59fb 100644
--- a/lib/chef/resource/lwrp_base.rb
+++ b/lib/chef/resource/lwrp_base.rb
@@ -39,7 +39,7 @@ class Chef
# Add log entry if we override an existing light-weight resource.
class_name = convert_to_class_name(rname)
- if Resource.const_defined?(class_name)
+ if Resource.const_defined?(class_name, false)
old_class = Resource.send(:remove_const, class_name)
# CHEF-3432 -- Chef::Resource keeps a list of subclasses; need to
# remove old ones from the list when replacing.
diff --git a/spec/data/lwrp_const_scoping/resources/conflict.rb b/spec/data/lwrp_const_scoping/resources/conflict.rb
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/spec/data/lwrp_const_scoping/resources/conflict.rb
diff --git a/spec/unit/lwrp_spec.rb b/spec/unit/lwrp_spec.rb
index 3e807bc06c..19d3504f3c 100644
--- a/spec/unit/lwrp_spec.rb
+++ b/spec/unit/lwrp_spec.rb
@@ -18,6 +18,8 @@
require 'spec_helper'
+module LwrpConstScopingConflict
+end
describe "LWRP" do
before do
@@ -72,6 +74,12 @@ describe "LWRP" do
Chef::Resource.resource_classes.should_not include(first_lwr_foo_class)
end
+ it "does not attempt to remove classes from higher up namespaces [CHEF-4117]" do
+ conflicting_lwrp_file = File.expand_path( "lwrp_const_scoping/resources/conflict.rb", CHEF_SPEC_DATA)
+ # The test is that this should not raise an error:
+ Chef::Resource::LWRPBase.build_from_file("lwrp_const_scoping", conflicting_lwrp_file, nil)
+ end
+
end
describe "Lightweight Chef::Resource" do