diff --git a/lib/cfa/augeas_parser.rb b/lib/cfa/augeas_parser.rb index fc3c42b..c49948d 100644 --- a/lib/cfa/augeas_parser.rb +++ b/lib/cfa/augeas_parser.rb @@ -323,6 +323,7 @@ def replace_entry(old_entry) @data.insert(index, new_entry) # the entry is not yet in the tree if old_entry[:operation] == :add + key = old_entry[:key] @data.delete_if { |d| d[:key] == key } else old_entry[:operation] = :remove diff --git a/spec/augeas_tree_spec.rb b/spec/augeas_tree_spec.rb index acbf767..e4624f2 100644 --- a/spec/augeas_tree_spec.rb +++ b/spec/augeas_tree_spec.rb @@ -70,6 +70,17 @@ tree["new_cool_key"] = "Ever cooler value" expect(tree["new_cool_key"]).to eq "Ever cooler value" end + + it "adds a new key and then overwrites it with a different kind" do + tree["shopping_cart"] = "orange" + + subtree = CFA::AugeasTree.new + subtree["item"] = "orange" + subtree["note"] = "paint, not fruit" + tree["shopping_cart"] = subtree + + expect(tree["shopping_cart"]["item"]).to eq "orange" + end end describe "#add" do