diff options
author | Thom May <thom@chef.io> | 2017-04-05 12:26:39 +0100 |
---|---|---|
committer | Thom May <thom@chef.io> | 2017-04-05 12:26:39 +0100 |
commit | 6480f1c173c4345f0ec333fa3de75da7139e3450 (patch) | |
tree | 0950a14e5641ded8651fcd6526f533f56f8ae13f | |
parent | ce64bc946883cb95a4cc26891bb64384e8f866c5 (diff) | |
download | chef-6480f1c173c4345f0ec333fa3de75da7139e3450.tar.gz |
Ensure DataBagItems are a Mashtm/mash_up_dem_dbi
closes: #5686
Signed-off-by: Thom May <thom@chef.io>
-rw-r--r-- | lib/chef/data_bag_item.rb | 3 | ||||
-rw-r--r-- | spec/unit/data_bag_item_spec.rb | 4 |
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 |