diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/unit/node/attribute_spec.rb | 24 | ||||
-rw-r--r-- | spec/unit/node/vivid_mash_spec.rb | 27 |
2 files changed, 50 insertions, 1 deletions
diff --git a/spec/unit/node/attribute_spec.rb b/spec/unit/node/attribute_spec.rb index e40f454c0b..00081a9fd9 100644 --- a/spec/unit/node/attribute_spec.rb +++ b/spec/unit/node/attribute_spec.rb @@ -1171,7 +1171,29 @@ describe Chef::Node::Attribute do Chef::Config[:treat_deprecation_warnings_as_errors] = false expect { @attributes.new_key = "new value" }.to raise_error(Chef::Exceptions::ImmutableAttributeModification) end - end + describe "deeply converting values" do + it "converts values through an array" do + @attributes.default[:foo] = [ { bar: true } ] + expect(@attributes["foo"].class).to eql(Chef::Node::ImmutableArray) + expect(@attributes["foo"][0].class).to eql(Chef::Node::ImmutableMash) + expect(@attributes["foo"][0]["bar"]).to be true + end + + it "converts values through nested arrays" do + @attributes.default[:foo] = [ [ { bar: true } ] ] + expect(@attributes["foo"].class).to eql(Chef::Node::ImmutableArray) + expect(@attributes["foo"][0].class).to eql(Chef::Node::ImmutableArray) + expect(@attributes["foo"][0][0].class).to eql(Chef::Node::ImmutableMash) + expect(@attributes["foo"][0][0]["bar"]).to be true + end + + it "converts values through nested hashes" do + @attributes.default[:foo] = { baz: { bar: true } } + expect(@attributes["foo"].class).to eql(Chef::Node::ImmutableMash) + expect(@attributes["foo"]["baz"].class).to eql(Chef::Node::ImmutableMash) + expect(@attributes["foo"]["baz"]["bar"]).to be true + end + end end diff --git a/spec/unit/node/vivid_mash_spec.rb b/spec/unit/node/vivid_mash_spec.rb index 5319ba4a35..206b15ef6c 100644 --- a/spec/unit/node/vivid_mash_spec.rb +++ b/spec/unit/node/vivid_mash_spec.rb @@ -37,6 +37,33 @@ describe Chef::Node::VividMash do expect(root).to receive(:top_level_breadcrumb=).with(key).at_least(:once).and_call_original end + context "#[]=" do + it "deep converts values through arrays" do + allow(root).to receive(:reset_cache) + vivid[:foo] = [ { :bar => true } ] + expect(vivid["foo"].class).to eql(Chef::Node::AttrArray) + expect(vivid["foo"][0].class).to eql(Chef::Node::VividMash) + expect(vivid["foo"][0]["bar"]).to be true + end + + it "deep converts values through nested arrays" do + allow(root).to receive(:reset_cache) + vivid[:foo] = [ [ { :bar => true } ] ] + expect(vivid["foo"].class).to eql(Chef::Node::AttrArray) + expect(vivid["foo"][0].class).to eql(Chef::Node::AttrArray) + expect(vivid["foo"][0][0].class).to eql(Chef::Node::VividMash) + expect(vivid["foo"][0][0]["bar"]).to be true + end + + it "deep converts values through hashes" do + allow(root).to receive(:reset_cache) + vivid[:foo] = { baz: { :bar => true } } + expect(vivid["foo"]).to be_an_instance_of(Chef::Node::VividMash) + expect(vivid["foo"]["baz"]).to be_an_instance_of(Chef::Node::VividMash) + expect(vivid["foo"]["baz"]["bar"]).to be true + end + end + context "#read" do before do # vivify the vividmash, then we're read-only so the cache should never be cleared afterwards |