diff options
Diffstat (limited to 'spec/unit/node/attribute_spec.rb')
-rw-r--r-- | spec/unit/node/attribute_spec.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/spec/unit/node/attribute_spec.rb b/spec/unit/node/attribute_spec.rb index 25594ca20b..0869b83e43 100644 --- a/spec/unit/node/attribute_spec.rb +++ b/spec/unit/node/attribute_spec.rb @@ -483,6 +483,24 @@ describe Chef::Node::Attribute do @attributes.default[:foo] = %w{foo bar baz} + Array(1..3) + [nil, true, false, [ "el", 0, nil ] ] @attributes.default[:foo].dup end + + it "mutating strings should not mutate the attributes in a hash" do + @attributes.default["foo"]["bar"]["baz"] = "fizz" + hash = @attributes["foo"].dup + expect(hash).to eql({ "bar" => { "baz" => "fizz" } }) + hash["bar"]["baz"] << "buzz" + expect(hash).to eql({ "bar" => { "baz" => "fizzbuzz" } }) + expect(@attributes.default["foo"]).to eql({ "bar" => { "baz" => "fizz" } }) + end + + it "mutating array elements should not mutate the attributes" do + @attributes.default["foo"]["bar"] = [ "fizz" ] + hash = @attributes["foo"].dup + expect(hash).to eql({ "bar" => [ "fizz" ] }) + hash["bar"][0] << "buzz" + expect(hash).to eql({ "bar" => [ "fizzbuzz" ] }) + expect(@attributes.default["foo"]).to eql({ "bar" => [ "fizz" ] }) + end end describe "has_key?" do |