diff options
-rw-r--r-- | lib/chef/data_bag_item.rb | 4 | ||||
-rw-r--r-- | spec/unit/data_bag_item_spec.rb | 7 |
2 files changed, 9 insertions, 2 deletions
diff --git a/lib/chef/data_bag_item.rb b/lib/chef/data_bag_item.rb index 0e3fa48e68..6ac863a47d 100644 --- a/lib/chef/data_bag_item.rb +++ b/lib/chef/data_bag_item.rb @@ -107,9 +107,9 @@ class Chef end def to_hash - result = self.raw_data + result = self.raw_data.dup result["chef_type"] = "data_bag_item" - result["data_bag"] = self.data_bag + result["data_bag"] = self.data_bag.to_s result end diff --git a/spec/unit/data_bag_item_spec.rb b/spec/unit/data_bag_item_spec.rb index ac4cf31b18..7f7d2b3013 100644 --- a/spec/unit/data_bag_item_spec.rb +++ b/spec/unit/data_bag_item_spec.rb @@ -146,6 +146,8 @@ describe Chef::DataBagItem do data_bag_item } + let!(:original_data_bag_keys) { data_bag_item.keys } + let(:to_hash) { data_bag_item.to_hash } it "should return a hash" do @@ -164,6 +166,11 @@ describe Chef::DataBagItem do it "should have the data_bag set" do expect(to_hash["data_bag"]).to eq("still_lost") end + + it "should not mutate the data_bag_item" do + data_bag_item.to_hash + expect(data_bag_item.keys).to eq(original_data_bag_keys) + end end describe "when deserializing from JSON" do |