Commit f6cff95d authored by Gilbert's avatar Gilbert
Browse files

Merge pull request #96 from brysgo/patch-1

Fix bug in array merge
parents ba636e70 6536ef04
......@@ -7,6 +7,7 @@ module StripeMock
desh_hash.merge(source_hash) do |key, oldval, newval|
if oldval.is_a?(Array) && newval.is_a?(Array)
oldval.fill(nil, oldval.length...newval.length)
oldval.zip(newval).map {|elems|
elems[1].nil? ? elems[0] : rmerge(elems[0], elems[1])
}
......
......@@ -26,6 +26,14 @@ describe StripeMock::Util do
expect(result).to eq({ x: [ {a: 0}, {a: 0, b: 2}, {c: 3} ] })
end
it "does not truncate the array when merging" do
dest = { x: [ {a: 1}, {b: 2} ] }
source = { x: [ nil, nil, {c: 3} ] }
result = StripeMock::Util.rmerge(dest, source)
expect(result).to eq({ x: [ {a: 1}, {b: 2}, {c: 3} ] })
end
it "treats an array nil element as a skip op" do
dest = { x: [ {a: 1}, {b: 2}, {c: 3} ] }
source = { x: [ nil, nil, {c: 0} ] }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment