Permalink
Browse files

Ensure that CollectionAssociation#replace returns proper target

The fix commited in e2a070c was returning the `new_target`, as
a try to return whatever user replaced association with. The
problem is, the resulting association target may be ordered
differently. In such case we want to return the target that
will be later used for that association.
  • Loading branch information...
1 parent ec77498 commit 099bb5d7b0e139d097b0c9bab4cdc8a36cf05ffa @drogus drogus committed May 18, 2012
@@ -476,7 +476,7 @@ def replace_records(new_target, original_target)
"new records could not be saved."
end
- new_target
+ target
end
def concat_records(records)
@@ -1572,14 +1572,14 @@ def test_replace
assert_equal [bulb2], car.reload.bulbs
end
- def test_replace_returns_new_target
+ def test_replace_returns_target
car = Car.create(:name => 'honda')
bulb1 = car.bulbs.create
bulb2 = car.bulbs.create
bulb3 = Bulb.create
assert_equal [bulb1, bulb2], car.bulbs
- result = car.bulbs.replace([bulb1, bulb3])
+ result = car.bulbs.replace([bulb3, bulb1])
assert_equal [bulb1, bulb3], car.bulbs
assert_equal [bulb1, bulb3], result
end

0 comments on commit 099bb5d

Please sign in to comment.