describe Skala::I18n::DeepMerger do describe ".deep_merge!" do describe "merges arrays into arrays" do it "merges two arrays of literals" do source = [1,"2",:f] destination = [:"3", 5, "foo"] described_class.deep_merge!(destination, source) expect(destination).to eq([:"3", 5, "foo", 1, "2", :f]) end it "merges two arrays of hashes" do source = [{c:3}] destination = [{a: 1}, {b:2}] described_class.deep_merge!(destination, source) expect(destination).to eq([{:a=>1}, {:b=>2}, {:c=>3}]) end end describe "merges hashes into hashes" do it "merges two simple hashes" do source = { c: 3 } destination = { a: 1, b: 2 } described_class.deep_merge!(destination, source) expect(destination).to eq({:a=>1, :b=>2, :c=>3}) end it "merges two nested hashes" do source = { a: { type: "multi_value", values: [2,3] }, b: { value: "123" } } destination = { a: { values: [1]}, b: { type: "id" } } described_class.deep_merge!(destination, source) expect(destination).to eq({:a=>{:values=>[1, 2, 3], :type=>"multi_value"}, :b=>{:type=>"id", :value=>"123"}}) end end end end