From d64164645d435e22fdab8179481acb89827dfe68 Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Fri, 18 May 2012 12:47:55 -0700 Subject: 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. --- activerecord/test/cases/associations/has_many_associations_test.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'activerecord/test/cases/associations/has_many_associations_test.rb') diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb index c128ede34f..4f50c97147 100644 --- a/activerecord/test/cases/associations/has_many_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_associations_test.rb @@ -1687,14 +1687,14 @@ class HasManyAssociationsTest < ActiveRecord::TestCase 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 -- cgit v1.2.3