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 4dd4621 commit d64164645d435e22fdab8179481acb89827dfe68 @drogus drogus committed May 18, 2012
@@ -492,7 +492,7 @@ def replace_records(new_target, original_target)
"new records could not be saved."
end
- new_target
+ target
end
def concat_records(records)
@@ -1687,14 +1687,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 d641646

Please sign in to comment.