summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThom May <thom@may.lt>2017-04-05 18:11:32 +0100
committerGitHub <noreply@github.com>2017-04-05 18:11:32 +0100
commit4a2bb2e5226a2aea9aa28e46a7f4f274b6871acd (patch)
treec4ca2b4be953a741bfc3eef5fbb2955a7085bcb7
parent770a567c6bcde849fa27054299a90a71fbb42985 (diff)
parent6480f1c173c4345f0ec333fa3de75da7139e3450 (diff)
downloadchef-4a2bb2e5226a2aea9aa28e46a7f4f274b6871acd.tar.gz
Merge pull request #6018 from chef/tm/mash_up_dem_dbi
Ensure DataBagItems are a Mash
-rw-r--r--lib/chef/data_bag_item.rb3
-rw-r--r--spec/unit/data_bag_item_spec.rb4
2 files changed, 6 insertions, 1 deletions
diff --git a/lib/chef/data_bag_item.rb b/lib/chef/data_bag_item.rb
index ddb520dc0b..d0fca26125 100644
--- a/lib/chef/data_bag_item.rb
+++ b/lib/chef/data_bag_item.rb
@@ -75,6 +75,7 @@ class Chef
end
def raw_data=(new_data)
+ new_data = Mash.new(new_data)
unless new_data.respond_to?(:[]) && new_data.respond_to?(:keys)
raise Exceptions::ValidationFailed, "Data Bag Items must contain a Hash or Mash!"
end
@@ -132,7 +133,7 @@ class Chef
item = new
item.data_bag(h.delete("data_bag")) if h.key?("data_bag")
if h.key?("raw_data")
- item.raw_data = Mash.new(h["raw_data"])
+ item.raw_data = h["raw_data"]
else
item.raw_data = h
end
diff --git a/spec/unit/data_bag_item_spec.rb b/spec/unit/data_bag_item_spec.rb
index e83f0ca0ec..7094a7b1f7 100644
--- a/spec/unit/data_bag_item_spec.rb
+++ b/spec/unit/data_bag_item_spec.rb
@@ -52,6 +52,10 @@ describe Chef::DataBagItem do
expect { data_bag_item.raw_data = { "id" => "octahedron" } }.not_to raise_error
end
+ it "should let you set the raw_data with a hash containing symbols" do
+ expect { data_bag_item.raw_data = { :id => "octahedron" } }.not_to raise_error
+ end
+
it "should let you set the raw_data from a mash" do
expect { data_bag_item.raw_data = Mash.new({ "id" => "octahedron" }) }.not_to raise_error
end