aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/nested_attributes_test.rb
diff options
context:
space:
mode:
authorNeeraj Singh <neerajdotname@gmail.com>2010-09-26 00:54:44 -0400
committerJosé Valim <jose.valim@gmail.com>2010-09-27 23:11:26 +0200
commit4966b915fe96db73933d33176c1ea5cc53e58a22 (patch)
tree60bc821af43c5d003a590dae4d835adda67b3ad7 /activerecord/test/cases/nested_attributes_test.rb
parent7f743233c4e276d1799451478e6718589d270cbd (diff)
downloadrails-4966b915fe96db73933d33176c1ea5cc53e58a22.tar.gz
rails-4966b915fe96db73933d33176c1ea5cc53e58a22.tar.bz2
rails-4966b915fe96db73933d33176c1ea5cc53e58a22.zip
Fix for #5579 involved the code change for both has_one and has_many relationships. The path included test only for has_one. This patch adds test for has_many relationship.
[#5706 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.rb10
1 files changed, 9 insertions, 1 deletions
diff --git a/activerecord/test/cases/nested_attributes_test.rb b/activerecord/test/cases/nested_attributes_test.rb
index 75ffd31de3..54429bf80b 100644
--- a/activerecord/test/cases/nested_attributes_test.rb
+++ b/activerecord/test/cases/nested_attributes_test.rb
@@ -115,7 +115,7 @@ class TestNestedAttributesInGeneral < ActiveRecord::TestCase
assert_difference('Ship.count') { pirate.save! }
end
- def test_reject_if_with_a_proc_which_returns_true_always
+ def test_reject_if_with_a_proc_which_returns_true_always_for_has_one
Pirate.accepts_nested_attributes_for :ship, :reject_if => proc {|attributes| true }
pirate = Pirate.new(:catchphrase => "Stop wastin' me time")
ship = pirate.create_ship(:name => 's1')
@@ -123,6 +123,14 @@ class TestNestedAttributesInGeneral < ActiveRecord::TestCase
assert_equal 's1', ship.reload.name
end
+ def test_reject_if_with_a_proc_which_returns_true_always_for_has_many
+ Man.accepts_nested_attributes_for :interests, :reject_if => proc {|attributes| true }
+ man = Man.create(:name => "John")
+ interest = man.interests.create(:topic => 'photography')
+ man.update_attributes({:interests_attributes => { :topic => 'gardening', :id => interest.id } })
+ assert_equal 'photography', interest.reload.topic
+ end
+
def test_has_many_association_updating_a_single_record
Man.accepts_nested_attributes_for(:interests)
man = Man.create(:name => 'John')