summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2018-01-25 12:52:13 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2018-01-25 12:52:13 -0800
commite56f8d58b80334256085907961aac9ca9f56f125 (patch)
treecd0841af833a7a49a37eb52a4abfa68b284f8b0f /spec
parent378eaf9a32fe339f34da16f3bef44f2ef18ea16a (diff)
downloadchef-e56f8d58b80334256085907961aac9ca9f56f125.tar.gz
fix node assignment of ImmutableArrays to VividMashes/AttrArrays
node.default['foo'] = node['bar'] need to have node['bar'] have its cache vivified otherwise we potentially get an empty hash or array. in the case of hashes, the assignment must have been walking though the values with #each or something which poked the cache on the target hash which caused it to vivify, so this bug only affected Arrays where the AttrArray initializer likely did a quick-n-dirty copy of the internal structure of the ImmutableArray which was empty. Signed-off-by: Lamont Granquist <lamont@scriptkiddie.org>
Diffstat (limited to 'spec')
-rw-r--r--spec/unit/node/attribute_spec.rb15
1 files changed, 15 insertions, 0 deletions
diff --git a/spec/unit/node/attribute_spec.rb b/spec/unit/node/attribute_spec.rb
index cbb9540486..42cdf2a9ce 100644
--- a/spec/unit/node/attribute_spec.rb
+++ b/spec/unit/node/attribute_spec.rb
@@ -1304,4 +1304,19 @@ describe Chef::Node::Attribute do
expect { @attributes["foo"]["bar"][0] << "buzz" }.to raise_error(RuntimeError, "can't modify frozen String")
end
end
+
+ describe "assigning lazy ungenerated caches to other attributes" do
+ it "works with arrays" do
+ @attributes.default["foo"]["baz"] = %w{one two}
+ @attributes.default["bar"]["baz"] = @attributes["foo"]["baz"]
+ expect(@attributes.default["bar"]["baz"]).to eql(%w{one two})
+ end
+
+ it "works with hashes" do
+ @attributes.default["foo"]["baz"] = { "one" => "two" }
+ @attributes.default["bar"]["baz"] = @attributes["foo"]["baz"]
+ expect(@attributes.default["bar"]["baz"]).to eql({ "one" => "two" })
+ end
+ end
+
end