aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases
diff options
context:
space:
mode:
authorPascal Ehlert <pascal.ehlert@odadata.eu>2009-02-04 09:24:02 +0100
committerMichael Koziarski <michael@koziarski.com>2009-02-06 13:36:59 +1300
commit455a7633dbdb295de828eb2657433d47d85eb0bc (patch)
tree27db0f1c1b1fe997e0290a35f83a7fcc92da2b14 /activerecord/test/cases
parent4e4f961c112f1ffac73a1397d94dfbb4a10effae (diff)
downloadrails-455a7633dbdb295de828eb2657433d47d85eb0bc.tar.gz
rails-455a7633dbdb295de828eb2657433d47d85eb0bc.tar.bz2
rails-455a7633dbdb295de828eb2657433d47d85eb0bc.zip
Nested attribute accessors should ignore new records with truthy _delete key.
Signed-off-by: Michael Koziarski <michael@koziarski.com> [#1861 state:committed]
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r--activerecord/test/cases/nested_attributes_test.rb14
1 files changed, 14 insertions, 0 deletions
diff --git a/activerecord/test/cases/nested_attributes_test.rb b/activerecord/test/cases/nested_attributes_test.rb
index 1605684677..2e531a284e 100644
--- a/activerecord/test/cases/nested_attributes_test.rb
+++ b/activerecord/test/cases/nested_attributes_test.rb
@@ -233,6 +233,20 @@ module NestedAttributesOnACollectionAssociationTests
assert_equal 'Privateers Greed', @pirate.send(@association_name).last.name
end
+ def test_should_remove_delete_key_from_arguments_hash_of_new_records
+ assert_nothing_raised ActiveRecord::UnknownAttributeError do
+ @pirate.send(association_setter, { 'new_1' => { '_delete' => '0' }})
+ end
+ end
+
+ def test_should_ignore_new_associated_records_with_truthy_delete_attribute
+ @pirate.send(@association_name).destroy_all
+ @pirate.reload.attributes = { association_getter => { 'new_1' => { :name => 'Grace OMalley' }, 'new_2' => { :name => 'Privateers Greed', '_delete' => '1' }}}
+
+ assert_equal 1, @pirate.send(@association_name).length
+ assert_equal 'Grace OMalley', @pirate.send(@association_name).first.name
+ end
+
def test_should_sort_the_hash_by_the_keys_before_building_new_associated_models
attributes = ActiveSupport::OrderedHash.new
attributes['new_123726353'] = { :name => 'Grace OMalley' }