aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/nested_attributes_test.rb
diff options
context:
space:
mode:
authorPratik Naik <pratiknaik@gmail.com>2009-10-07 23:50:30 +0100
committerPratik Naik <pratiknaik@gmail.com>2009-10-07 23:50:30 +0100
commit572323135f235cc43e8a5bbafa3a634b4ec71ba8 (patch)
tree69782afc2de5b999d550c8a7bfc21420e06d73c0 /activerecord/test/cases/nested_attributes_test.rb
parent9415935902f120a9bac0bfce7129725a0db38ed3 (diff)
downloadrails-572323135f235cc43e8a5bbafa3a634b4ec71ba8.tar.gz
rails-572323135f235cc43e8a5bbafa3a634b4ec71ba8.tar.bz2
rails-572323135f235cc43e8a5bbafa3a634b4ec71ba8.zip
Allow accepts_nested_attributes_for :reject_if option accept symbols for using a method
Conflicts: activerecord/lib/active_record/nested_attributes.rb
Diffstat (limited to 'activerecord/test/cases/nested_attributes_test.rb')
-rw-r--r--activerecord/test/cases/nested_attributes_test.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/activerecord/test/cases/nested_attributes_test.rb b/activerecord/test/cases/nested_attributes_test.rb
index 721792132c..bf9aa4e65f 100644
--- a/activerecord/test/cases/nested_attributes_test.rb
+++ b/activerecord/test/cases/nested_attributes_test.rb
@@ -84,6 +84,26 @@ class TestNestedAttributesInGeneral < ActiveRecord::TestCase
ship = Ship.create!(:name => 'Nights Dirty Lightning')
ship._delete
end
+
+ def test_reject_if_method_without_arguments
+ Pirate.accepts_nested_attributes_for :ship, :reject_if => :new_record?
+
+ pirate = Pirate.new(:catchphrase => "Stop wastin' me time")
+ pirate.ship_attributes = { :name => 'Black Pearl' }
+ assert_no_difference('Ship.count') { pirate.save! }
+ end
+
+ def test_reject_if_method_with_arguments
+ Pirate.accepts_nested_attributes_for :ship, :reject_if => :reject_empty_ships_on_create
+
+ pirate = Pirate.new(:catchphrase => "Stop wastin' me time")
+ pirate.ship_attributes = { :name => 'Red Pearl', :_reject_me_if_new => true }
+ assert_no_difference('Ship.count') { pirate.save! }
+
+ # pirate.reject_empty_ships_on_create returns false for saved records
+ pirate.ship_attributes = { :name => 'Red Pearl', :_reject_me_if_new => true }
+ assert_difference('Ship.count') { pirate.save! }
+ end
end
class TestNestedAttributesOnAHasOneAssociation < ActiveRecord::TestCase