Skip to content

Commit

Permalink
Normalizing the attribute hash names, fixing spec
Browse files Browse the repository at this point in the history
  • Loading branch information
adamhjk committed Apr 16, 2010
1 parent db3eeb5 commit 92e5cf1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
15 changes: 9 additions & 6 deletions chef/lib/chef/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -356,10 +356,10 @@ def to_json(*a)
result = {
"name" => @name,
'json_class' => self.class.name,
"attributes" => @normal_attrs,
"normal" => @normal_attrs,
"chef_type" => "node",
"defaults" => @default_attrs,
"overrides" => @override_attrs,
"default" => @default_attrs,
"override" => @override_attrs,
"run_list" => @run_list.run_list,
}
result["_rev"] = @couchdb_rev if @couchdb_rev
Expand All @@ -370,9 +370,12 @@ def to_json(*a)
def self.json_create(o)
node = new
node.name(o["name"])
node.normal_attrs = Mash.new(o["attributes"]) if o.has_key?("attributes")
node.default_attrs = Mash.new(o["defaults"]) if o.has_key?("defaults")
node.override_attrs = Mash.new(o["overrides"]) if o.has_key?("overrides")
if o.has_key?("attributes")
node.normal_attrs = o["attributes"]
end
node.normal_attrs = Mash.new(o["normal"]) if o.has_key?("normal")
node.default_attrs = Mash.new(o["default"]) if o.has_key?("default")
node.override_attrs = Mash.new(o["override"]) if o.has_key?("override")

if o.has_key?("run_list")
node.run_list.reset!(o["run_list"])
Expand Down
6 changes: 3 additions & 3 deletions chef/spec/unit/node_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -344,9 +344,9 @@
json = @node.to_json()
json.should =~ /json_class/
json.should =~ /name/
json.should =~ /attributes/
json.should =~ /overrides/
json.should =~ /defaults/
json.should =~ /normal/
json.should =~ /default/
json.should =~ /override/
json.should =~ /run_list/
end

Expand Down

0 comments on commit 92e5cf1

Please sign in to comment.