summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2014-11-20 19:07:52 -0800
committerLamont Granquist <lamont@scriptkiddie.org>2014-11-20 19:07:52 -0800
commit5c86c554f1a08cdc39abcacbb43107c597b6d14a (patch)
tree91cc90ab80d44e421ceabcf73dd844852056b239
parent346aff0078a676d8c05319c017b891184426d004 (diff)
downloadchef-lcg/to-hash-specs.tar.gz
adding some more specs around to_hashlcg/to-hash-specs
-rw-r--r--spec/unit/node/attribute_spec.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/spec/unit/node/attribute_spec.rb b/spec/unit/node/attribute_spec.rb
index 39e40a465f..c924ee2811 100644
--- a/spec/unit/node/attribute_spec.rb
+++ b/spec/unit/node/attribute_spec.rb
@@ -486,6 +486,34 @@ describe Chef::Node::Attribute do
expect(hash.class).to eq(Hash)
expect(hash["day"]).to eq("sunday")
end
+
+ it "should create a deep copy of the node attribute" do
+ @attributes.default['foo']['bar']['baz'] = 'fizz'
+ hash = @attributes['foo'].to_hash
+ expect(hash).to eql({"bar"=>{"baz"=>"fizz"}})
+ hash['bar']['baz'] = 'buzz'
+ expect(hash).to eql({"bar"=>{"baz"=>"buzz"}})
+ expect(@attributes.default['foo']).to eql({"bar"=>{"baz"=>"fizz"}})
+ end
+
+ it "should create a deep copy of arrays in the node attribute" do
+ @attributes.default['foo']['bar'] = ['fizz']
+ hash = @attributes['foo'].to_hash
+ expect(hash).to eql({"bar"=>[ 'fizz' ]})
+ hash['bar'].push('buzz')
+ expect(hash).to eql({"bar"=>[ 'fizz', 'buzz' ]})
+ expect(@attributes.default['foo']).to eql({"bar"=>[ 'fizz' ]})
+ end
+
+ it "mutating strings should not mutate the attributes" do
+ pending "this is a bug that should be fixed"
+ @attributes.default['foo']['bar']['baz'] = 'fizz'
+ hash = @attributes['foo'].to_hash
+ 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
end
describe "dup" do