aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/nested_attributes_test.rb
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2010-04-14 01:51:43 +0100
committerPratik Naik <pratiknaik@gmail.com>2010-04-14 01:52:29 +0100
commit2ff5f38abb4a44ed5356c34b40d30d446fb63408 (patch)
treef2c6427e5531d5b1b2515610487600a779175e0a /activerecord/test/cases/nested_attributes_test.rb
parent5208cc3cf5d54720512ff50c2b97e9f4369aaa27 (diff)
downloadrails-2ff5f38abb4a44ed5356c34b40d30d446fb63408.tar.gz
rails-2ff5f38abb4a44ed5356c34b40d30d446fb63408.tar.bz2
rails-2ff5f38abb4a44ed5356c34b40d30d446fb63408.zip
Ensure not to load the entire association when bulk updating existing records using nested attributes
Diffstat (limited to 'activerecord/test/cases/nested_attributes_test.rb')
-rw-r--r--activerecord/test/cases/nested_attributes_test.rb12
1 files changed, 11 insertions, 1 deletions
diff --git a/activerecord/test/cases/nested_attributes_test.rb b/activerecord/test/cases/nested_attributes_test.rb
index 7ca9c416cb..eae8ae7e39 100644
--- a/activerecord/test/cases/nested_attributes_test.rb
+++ b/activerecord/test/cases/nested_attributes_test.rb
@@ -453,6 +453,16 @@ module NestedAttributesOnACollectionAssociationTests
assert_equal 'Privateers Greed', @pirate.send(@association_name).last.name
end
+ def test_should_not_load_association_when_updating_existing_records
+ @pirate.reload
+ @pirate.send(association_setter, [{ :id => @child_1.id, :name => 'Grace OMalley' }])
+ assert ! @pirate.send(@association_name).loaded?
+
+ @pirate.save
+ assert ! @pirate.send(@association_name).loaded?
+ assert_equal 'Grace OMalley', @child_1.reload.name
+ end
+
def test_should_take_a_hash_with_composite_id_keys_and_assign_the_attributes_to_the_associated_models
@child_1.stubs(:id).returns('ABC1X')
@child_2.stubs(:id).returns('ABC2X')
@@ -507,7 +517,7 @@ module NestedAttributesOnACollectionAssociationTests
def test_should_ignore_new_associated_records_if_a_reject_if_proc_returns_false
@alternate_params[association_getter]['baz'] = {}
- assert_no_difference("@pirate.send(@association_name).length") do
+ assert_no_difference("@pirate.send(@association_name).count") do
@pirate.attributes = @alternate_params
end
end