From 8510a0bb5a8a65e4bc067ee5a7d98aae965b47a5 Mon Sep 17 00:00:00 2001 From: Aaron Christy Date: Sat, 15 Oct 2011 19:53:36 -0400 Subject: Exclude _destroy parameter in :all_blank check (issue #2937) --- activerecord/test/cases/nested_attributes_test.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'activerecord/test/cases/nested_attributes_test.rb') diff --git a/activerecord/test/cases/nested_attributes_test.rb b/activerecord/test/cases/nested_attributes_test.rb index 67a9ed6cd8..2ae9cb4888 100644 --- a/activerecord/test/cases/nested_attributes_test.rb +++ b/activerecord/test/cases/nested_attributes_test.rb @@ -45,6 +45,14 @@ class TestNestedAttributesInGeneral < ActiveRecord::TestCase end end + def test_should_not_build_a_new_record_using_reject_all_even_if_destroy_is_given + pirate = Pirate.create!(:catchphrase => "Don' botharrr talkin' like one, savvy?") + pirate.birds_with_reject_all_blank_attributes = [{:name => '', :color => '', :_destroy => '0'}] + pirate.save! + + assert pirate.birds_with_reject_all_blank.empty? + end + def test_should_not_build_a_new_record_if_reject_all_blank_returns_false pirate = Pirate.create!(:catchphrase => "Don' botharrr talkin' like one, savvy?") pirate.birds_with_reject_all_blank_attributes = [{:name => '', :color => ''}] -- cgit v1.2.3 From 774ff18c095145f544e845dbb940378546748969 Mon Sep 17 00:00:00 2001 From: Andrew Kaspick Date: Wed, 14 Dec 2011 20:13:03 -0600 Subject: Allow nested attributes in associations to update values in it's owner object. Fixes a regression from 3.0.x --- activerecord/test/cases/nested_attributes_test.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'activerecord/test/cases/nested_attributes_test.rb') diff --git a/activerecord/test/cases/nested_attributes_test.rb b/activerecord/test/cases/nested_attributes_test.rb index 2ae9cb4888..2f28dd4767 100644 --- a/activerecord/test/cases/nested_attributes_test.rb +++ b/activerecord/test/cases/nested_attributes_test.rb @@ -617,6 +617,11 @@ module NestedAttributesOnACollectionAssociationTests assert_equal ['Grace OMalley', 'Privateers Greed'], [@child_1.name, @child_2.name] end + def test_should_take_a_hash_with_owner_attributes_and_assign_the_attributes_to_the_associated_model + @pirate.birds.create :name => 'bird', :pirate_attributes => {:id => @pirate.id.to_s, :catchphrase => 'Holla!'} + assert_equal 'Holla!', @pirate.reload.catchphrase + end + def test_should_raise_RecordNotFound_if_an_id_is_given_but_doesnt_return_a_record assert_raise_with_message ActiveRecord::RecordNotFound, "Couldn't find #{@child_1.class.name} with ID=1234567890 for Pirate with ID=#{@pirate.id}" do @pirate.attributes = { association_getter => [{ :id => 1234567890 }] } -- cgit v1.2.3 From 1ad0a5363bcf44da9ed51e30c5c47a83c3516c24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Ku=C5=BAma?= Date: Wed, 21 Dec 2011 15:28:24 +0100 Subject: added failing tests for has_many, has_one and belongs_to associations with strict mass assignment sanitizer, fixed build_record to not merge creation_attributes, removed failing nested attributes tests (that feature was broken anyway) #4051 --- activerecord/test/cases/nested_attributes_test.rb | 5 ----- 1 file changed, 5 deletions(-) (limited to 'activerecord/test/cases/nested_attributes_test.rb') diff --git a/activerecord/test/cases/nested_attributes_test.rb b/activerecord/test/cases/nested_attributes_test.rb index 2f28dd4767..2ae9cb4888 100644 --- a/activerecord/test/cases/nested_attributes_test.rb +++ b/activerecord/test/cases/nested_attributes_test.rb @@ -617,11 +617,6 @@ module NestedAttributesOnACollectionAssociationTests assert_equal ['Grace OMalley', 'Privateers Greed'], [@child_1.name, @child_2.name] end - def test_should_take_a_hash_with_owner_attributes_and_assign_the_attributes_to_the_associated_model - @pirate.birds.create :name => 'bird', :pirate_attributes => {:id => @pirate.id.to_s, :catchphrase => 'Holla!'} - assert_equal 'Holla!', @pirate.reload.catchphrase - end - def test_should_raise_RecordNotFound_if_an_id_is_given_but_doesnt_return_a_record assert_raise_with_message ActiveRecord::RecordNotFound, "Couldn't find #{@child_1.class.name} with ID=1234567890 for Pirate with ID=#{@pirate.id}" do @pirate.attributes = { association_getter => [{ :id => 1234567890 }] } -- cgit v1.2.3