Permalink
Browse files

add tests surrounding behavior of save and save! for associations tha…

…t have validation errors
  • Loading branch information...
1 parent f0c09f7 commit 1c079c5fd78d55be45436fb510ffc19564dc26ed @tenderlove tenderlove committed May 24, 2011
Showing with 26 additions and 0 deletions.
  1. +26 −0 activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -503,6 +503,14 @@ def test_create_should_not_raise_exception_when_join_record_has_errors
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' }
@@ -511,4 +519,22 @@ def test_create_bang_should_raise_exception_when_join_record_has_errors
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

0 comments on commit 1c079c5

Please sign in to comment.