diff --git a/lib/chef/knife/topo/node_update_helper.rb b/lib/chef/knife/topo/node_update_helper.rb index 8a35ef3..70fe158 100644 --- a/lib/chef/knife/topo/node_update_helper.rb +++ b/lib/chef/knife/topo/node_update_helper.rb @@ -81,7 +81,7 @@ def update_node_with_values(node, updates) def update_attrs(node, attrs) return false unless attrs attrs.delete('tags') - original = node.normal.clone + original = Marshal.load(Marshal.dump(node.normal)) node.normal = Chef::Mixin::DeepMerge.merge(node.normal, attrs) original != node.normal end diff --git a/lib/chef/knife/topo/version.rb b/lib/chef/knife/topo/version.rb index 663b552..9be208b 100644 --- a/lib/chef/knife/topo/version.rb +++ b/lib/chef/knife/topo/version.rb @@ -1,4 +1,4 @@ # version module KnifeTopo - VERSION = '2.0.2' + VERSION = '2.0.3' end diff --git a/spec/unit/topo_update_spec.rb b/spec/unit/topo_update_spec.rb index 8e5a070..cacb42c 100644 --- a/spec/unit/topo_update_spec.rb +++ b/spec/unit/topo_update_spec.rb @@ -171,5 +171,13 @@ @cmd.update_node_with_values(node, 'normal' => { 'attr1' => 'val2' }) expect(node['attr1']).to eq('val2') end + + it 'detects and saves change in nested attributes' do + node = Chef::Node.new + node.normal = { 'level1' => { 'level2' => { 'attr1' => 'val1' } } } + expect(node).to receive(:save) + @cmd.do_node_updates(node, 'normal' => { 'level1' => + { 'level2' => { 'attr1' => 'val2' } } }) + end end end