Permalink
Browse files

Fix CollectionAssociation#replace to return new target (closes #6231)

  • Loading branch information...
1 parent 1f0e2de commit e2a070cf47fb9a845ecf53ff2f437390598fe0b7 @drogus drogus committed May 10, 2012
@@ -468,6 +468,8 @@ def replace_records(new_target, original_target)
raise RecordNotSaved, "Failed to replace #{reflection.name} because one or more of the " \
"new records could not be saved."
end
+
+ new_target
end
def concat_records(records)
@@ -1685,6 +1685,18 @@ def test_replace
assert_equal [bulb2], car.reload.bulbs
end
+ def test_replace_returns_new_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])
+ assert_equal [bulb1, bulb3], car.bulbs
+ assert_equal [bulb1, bulb3], result
+ end
+
def test_building_has_many_association_with_restrict_dependency
option_before = ActiveRecord::Base.dependent_restrict_raises
ActiveRecord::Base.dependent_restrict_raises = true

0 comments on commit e2a070c

Please sign in to comment.