diff options
author | Mike Breen <hardbap@gmail.com> | 2009-05-10 15:02:00 +1200 |
---|---|---|
committer | Michael Koziarski <michael@koziarski.com> | 2009-05-10 15:02:00 +1200 |
commit | 9010ed27559ed5ab89ea71b4b16f4c8e56d03dbb (patch) | |
tree | cc6198a10a89e8a7017f2f38368e94bdd8348ad6 /activerecord/test/cases | |
parent | 026b78f9076216990bddb1aa5d83d23a647c02a5 (diff) | |
download | rails-9010ed27559ed5ab89ea71b4b16f4c8e56d03dbb.tar.gz rails-9010ed27559ed5ab89ea71b4b16f4c8e56d03dbb.tar.bz2 rails-9010ed27559ed5ab89ea71b4b16f4c8e56d03dbb.zip |
Allow you to pass :all_blank to :reject_if option to automatically create a Proc that will reject any record with blank attributes.
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/nested_attributes_test.rb | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/activerecord/test/cases/nested_attributes_test.rb b/activerecord/test/cases/nested_attributes_test.rb index cd6277c24b..f1741ed54d 100644 --- a/activerecord/test/cases/nested_attributes_test.rb +++ b/activerecord/test/cases/nested_attributes_test.rb @@ -31,11 +31,27 @@ class TestNestedAttributesInGeneral < ActiveRecord::TestCase end def test_should_add_a_proc_to_reject_new_nested_attributes_procs - [:parrots, :birds].each do |name| + [:parrots, :birds, :birds_with_reject_all_blank].each do |name| assert_instance_of Proc, Pirate.reject_new_nested_attributes_procs[name] end 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 => ''}] + pirate.save! + + assert pirate.birds_with_reject_all_blank.empty? + end + + def test_should_build_a_new_record_if_reject_all_blank_does_not_return_false + pirate = Pirate.create!(:catchphrase => "Don' botharrr talkin' like one, savvy?") + pirate.birds_with_reject_all_blank_attributes = [{:name => 'Tweetie', :color => ''}] + pirate.save! + + assert_equal 1, pirate.birds_with_reject_all_blank.count + end + def test_should_raise_an_ArgumentError_for_non_existing_associations assert_raise_with_message ArgumentError, "No association found for name `honesty'. Has it been defined yet?" do Pirate.accepts_nested_attributes_for :honesty |