summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordanielsdeleo <dan@chef.io>2015-09-14 19:15:41 -0700
committerdanielsdeleo <dan@chef.io>2015-09-17 14:29:50 -0700
commitf21715037c1fc9956738ba069760f3c7615987ce (patch)
treeeb3d0f4a2d91d4a244efd14611d616d2b42d8dac
parente441d37d36eedbd73b37166f982536b8702ff4fb (diff)
downloadchef-f21715037c1fc9956738ba069760f3c7615987ce.tar.gz
Populate node policyfile attrs from JSON
-rw-r--r--lib/chef/node.rb4
-rw-r--r--spec/unit/node_spec.rb8
2 files changed, 12 insertions, 0 deletions
diff --git a/lib/chef/node.rb b/lib/chef/node.rb
index 3c3286c548..668ddbdc35 100644
--- a/lib/chef/node.rb
+++ b/lib/chef/node.rb
@@ -549,6 +549,10 @@ class Chef
else
o["recipes"].each { |r| node.recipes << r }
end
+
+ node.policy_name = o["policy_name"] if o.has_key?("policy_name")
+ node.policy_group = o["policy_group"] if o.has_key?("policy_group")
+
node
end
diff --git a/spec/unit/node_spec.rb b/spec/unit/node_spec.rb
index 91177233a8..5f3bed2833 100644
--- a/spec/unit/node_spec.rb
+++ b/spec/unit/node_spec.rb
@@ -1212,6 +1212,14 @@ describe Chef::Node do
expect(node.for_json).to have_key("policy_group")
expect(node.for_json["policy_group"]).to eq("staging")
end
+
+ it "parses policyfile attributes from JSON" do
+ round_tripped_node = Chef::Node.json_create(node.for_json)
+
+ expect(round_tripped_node.policy_name).to eq("my-application")
+ expect(round_tripped_node.policy_group).to eq("staging")
+ end
+
end
include_examples "to_json equivalent to Chef::JSONCompat.to_json" do