aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-09-26 10:41:11 +0100
committerJon Leighton <j@jonathanleighton.com>2011-09-26 10:41:58 +0100
commitb838059817aca490f78e3bb74a070729270300db (patch)
tree166e26d4689fa8a296765471aacb22f76e969491 /activerecord/test
parent541018a07b6467bee5e22709ce7dc46880ea1ff4 (diff)
downloadrails-b838059817aca490f78e3bb74a070729270300db.tar.gz
rails-b838059817aca490f78e3bb74a070729270300db.tar.bz2
rails-b838059817aca490f78e3bb74a070729270300db.zip
CollectionProxy#replace should change the DB records rather than just mutating the array. Fixes #3020.
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/associations/has_many_associations_test.rb11
1 files changed, 11 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 1e59931963..682e145828 100644
--- a/activerecord/test/cases/associations/has_many_associations_test.rb
+++ b/activerecord/test/cases/associations/has_many_associations_test.rb
@@ -1578,4 +1578,15 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
assert_equal car.id, bulb.attributes_after_initialize['car_id']
end
+
+ def test_replace
+ car = Car.create(:name => 'honda')
+ bulb1 = car.bulbs.create
+ bulb2 = Bulb.create
+
+ assert_equal [bulb1], car.bulbs
+ car.bulbs.replace([bulb2])
+ assert_equal [bulb2], car.bulbs
+ assert_equal [bulb2], car.reload.bulbs
+ end
end