Permalink
Browse files

CollectionProxy#replace should change the DB records rather than just…

… mutating the array. Fixes #3020.
  • Loading branch information...
1 parent 541018a commit b838059817aca490f78e3bb74a070729270300db @jonleighton jonleighton committed Sep 26, 2011
@@ -46,7 +46,7 @@ class CollectionProxy # :nodoc:
delegate :select, :find, :first, :last,
:build, :create, :create!,
- :concat, :delete_all, :destroy_all, :delete, :destroy, :uniq,
+ :concat, :replace, :delete_all, :destroy_all, :delete, :destroy, :uniq,
:sum, :count, :size, :length, :empty?,
:any?, :many?, :include?,
:to => :@association
@@ -1578,4 +1578,15 @@ def test_association_attributes_are_available_to_after_initialize
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

0 comments on commit b838059

Please sign in to comment.