aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorPiotr Sarnacki <drogus@gmail.com>2012-05-09 19:35:34 -0700
committerPiotr Sarnacki <drogus@gmail.com>2012-05-16 17:22:44 -0700
commite2a070cf47fb9a845ecf53ff2f437390598fe0b7 (patch)
tree584b82c8f513676baa6cc134234eb1cfb4fd431d /activerecord/test
parent1f0e2de8670587a75453f064cf384c2382c88526 (diff)
downloadrails-e2a070cf47fb9a845ecf53ff2f437390598fe0b7.tar.gz
rails-e2a070cf47fb9a845ecf53ff2f437390598fe0b7.tar.bz2
rails-e2a070cf47fb9a845ecf53ff2f437390598fe0b7.zip
Fix CollectionAssociation#replace to return new target (closes #6231)
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/associations/has_many_associations_test.rb12
1 files changed, 12 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_many_associations_test.rb b/activerecord/test/cases/associations/has_many_associations_test.rb
index 13d8c68b33..2e24f8ebe1 100644
--- a/activerecord/test/cases/associations/has_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_associations_test.rb
@@ -1685,6 +1685,18 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
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