Permalink
Browse files

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

… mutating the array. Fixes #3020.

Conflicts:

	activerecord/test/cases/associations/has_many_associations_test.rb
  • Loading branch information...
1 parent a61d85c commit 2d7dd9b1e405fe4ceed7ad034c8e981e1db942ef @jonleighton jonleighton committed Sep 26, 2011
View
@@ -1,5 +1,10 @@
*Rails 3.1.1 (unreleased)*
+* CollectionProxy#replace should change the DB records rather than just mutating the array.
+ Fixes #3020.
+
+ [Jon Leighton]
+
* LRU cache in mysql and sqlite are now per-process caches.
* lib/active_record/connection_adapters/mysql_adapter.rb: LRU cache
@@ -53,7 +53,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
@@ -1516,6 +1516,7 @@ def test_association_attributes_are_available_to_after_initialize
assert_equal car.id, bulb.attributes_after_initialize['car_id']
end
+<<<<<<< HEAD
@ugisozols

ugisozols Sep 26, 2011

Contributor

This probably shouldn't be here :)

@vijaydev

vijaydev Sep 26, 2011

Member

Fixed in 7d603ff. Thanks.

@jonleighton

jonleighton Sep 26, 2011

Member

Ha, thanks for catching that ;)

def test_overriding_reflection_build_association_with_deprecated_method_signature
ActiveRecord::Reflection::AssociationReflection.class_eval do
alias_method :old_build_association, :build_association
@@ -1554,4 +1555,15 @@ def foo
end
end
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 2d7dd9b

Please sign in to comment.