aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/nested_attributes_test.rb
diff options
context:
space:
mode:
authorSzetobo <szetobo@gmail.com>2010-07-12 09:47:47 +0800
committerJosé Valim <jose.valim@gmail.com>2010-07-21 14:25:27 +0200
commit0057d2df71ec7c2a788acd3b4bade263fc0fe361 (patch)
tree786e912e4da78b5f86ec16f8fbec9b6499c3b7e7 /activerecord/test/cases/nested_attributes_test.rb
parentc0bfa0bfc17f4aa615cd9d1006509e0d84b5692d (diff)
downloadrails-0057d2df71ec7c2a788acd3b4bade263fc0fe361.tar.gz
rails-0057d2df71ec7c2a788acd3b4bade263fc0fe361.tar.bz2
rails-0057d2df71ec7c2a788acd3b4bade263fc0fe361.zip
association load target shouldn't replace records
from db if it is already loaded by nested attributes assignment [#5053 state:resolved] Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activerecord/test/cases/nested_attributes_test.rb')
-rw-r--r--activerecord/test/cases/nested_attributes_test.rb14
1 files changed, 13 insertions, 1 deletions
diff --git a/activerecord/test/cases/nested_attributes_test.rb b/activerecord/test/cases/nested_attributes_test.rb
index 20bd4f6a76..df09bbd46a 100644
--- a/activerecord/test/cases/nested_attributes_test.rb
+++ b/activerecord/test/cases/nested_attributes_test.rb
@@ -862,7 +862,19 @@ class TestHasManyAutosaveAssociationWhichItselfHasAutosaveAssociations < ActiveR
assert_equal 1, @ship.parts.proxy_target.size
assert_equal 'Deck', @ship.parts[0].name
end
-
+
+ test "if association is not loaded and child doesn't change and I am saving a grandchild then in memory record should be used" do
+ @ship.parts_attributes=[{:id => @part.id,:trinkets_attributes =>[{:id => @trinket.id, :name => 'Ruby'}]}]
+ assert_equal 1, @ship.parts.proxy_target.size
+ assert_equal 'Mast', @ship.parts[0].name
+ assert_no_difference("@ship.parts[0].trinkets.proxy_target.size") do
+ @ship.parts[0].trinkets.proxy_target.size
+ end
+ assert_equal 'Ruby', @ship.parts[0].trinkets[0].name
+ @ship.save
+ assert_equal 'Ruby', @ship.parts[0].trinkets[0].name
+ end
+
test "when grandchild changed in memory, saving parent should save grandchild" do
@trinket.name = "changed"
@ship.save