diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-05-24 11:21:24 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-05-24 11:21:24 -0700 |
commit | 559d809609570466ea1f86b0255e0269b43a2a3b (patch) | |
tree | 4a7f69b28c7865bfc7dc415a07b10397993d4b0f /activerecord/test | |
parent | 964338777d183fdbf408a09ae6d7426ac8aaf96c (diff) | |
download | rails-559d809609570466ea1f86b0255e0269b43a2a3b.tar.gz rails-559d809609570466ea1f86b0255e0269b43a2a3b.tar.bz2 rails-559d809609570466ea1f86b0255e0269b43a2a3b.zip |
add tests surrounding behavior of save and save! for associations that have validation errors
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/associations/has_many_through_associations_test.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/activerecord/test/cases/associations/has_many_through_associations_test.rb b/activerecord/test/cases/associations/has_many_through_associations_test.rb index a2a25b5b85..877148bd5e 100644 --- a/activerecord/test/cases/associations/has_many_through_associations_test.rb +++ b/activerecord/test/cases/associations/has_many_through_associations_test.rb @@ -774,6 +774,14 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase end end + def test_save_should_not_raise_exception_when_join_record_has_errors + repair_validations(Categorization) do + Categorization.validate { |r| r.errors[:base] << 'Invalid Categorization' } + c = Category.create(:name => 'Fishing', :authors => [Author.first]) + c.save + end + end + def test_create_bang_should_raise_exception_when_join_record_has_errors repair_validations(Categorization) do Categorization.validate { |r| r.errors[:base] << 'Invalid Categorization' } @@ -782,4 +790,22 @@ class HasManyThroughAssociationsTest < ActiveRecord::TestCase end end end + + def test_save_bang_should_raise_exception_when_join_record_has_errors + repair_validations(Categorization) do + Categorization.validate { |r| r.errors[:base] << 'Invalid Categorization' } + c = Category.new(:name => 'Fishing', :authors => [Author.first]) + assert_raises(ActiveRecord::RecordInvalid) do + c.save! + end + end + end + + def test_create_bang_returns_falsy_when_join_record_has_errors + repair_validations(Categorization) do + Categorization.validate { |r| r.errors[:base] << 'Invalid Categorization' } + c = Category.new(:name => 'Fishing', :authors => [Author.first]) + assert !c.save + end + end end |