diff options
author | Lamont Granquist <lamont@scriptkiddie.org> | 2018-01-25 14:06:48 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-25 14:06:48 -0800 |
commit | 9566576a9502550878c3a089345e778d1b84430c (patch) | |
tree | 1bbbdaeca7a30cc560c88f55d2ce35d67f7820fa | |
parent | 4997ad7707714cbfd35acef398f17fa133bed053 (diff) | |
parent | 1446e9f8202f87cf646053760ce41fc0aa938e21 (diff) | |
download | chef-9566576a9502550878c3a089345e778d1b84430c.tar.gz |
Merge pull request #6791 from chef/lcg/fix-attr-assignment-to-attrs-13
fix node assignment of ImmutableArrays to VividMashes/AttrArrays (Chef-13 backport)
-rw-r--r-- | lib/chef/node/attribute_collections.rb | 2 | ||||
-rw-r--r-- | lib/chef/node/mixin/state_tracking.rb | 2 | ||||
-rw-r--r-- | spec/unit/node/attribute_spec.rb | 15 |
3 files changed, 18 insertions, 1 deletions
diff --git a/lib/chef/node/attribute_collections.rb b/lib/chef/node/attribute_collections.rb index bb32ae3b54..9e4a56b37d 100644 --- a/lib/chef/node/attribute_collections.rb +++ b/lib/chef/node/attribute_collections.rb @@ -92,6 +92,7 @@ class Chef private def convert_value(value) + value.ensure_generated_cache! if value.respond_to?(:ensure_generated_cache!) case value when VividMash value @@ -189,6 +190,7 @@ class Chef # AttrArray for consistency and to ensure that the added parts of the # attribute tree will have the correct cache invalidation behavior. def convert_value(value) + value.ensure_generated_cache! if value.respond_to?(:ensure_generated_cache!) case value when VividMash value diff --git a/lib/chef/node/mixin/state_tracking.rb b/lib/chef/node/mixin/state_tracking.rb index 690d261df6..0c3d4c33a4 100644 --- a/lib/chef/node/mixin/state_tracking.rb +++ b/lib/chef/node/mixin/state_tracking.rb @@ -1,5 +1,5 @@ #-- -# Copyright:: Copyright 2016-2017, Chef Software Inc. +# Copyright:: Copyright 2016-2018, Chef Software Inc. # License:: Apache License, Version 2.0 # # Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/spec/unit/node/attribute_spec.rb b/spec/unit/node/attribute_spec.rb index 90b3f1fe51..a9dab144ab 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 |