Permalink
Browse files

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

…t have validation errors
  • Loading branch information...
1 parent 9643387 commit 559d809609570466ea1f86b0255e0269b43a2a3b @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
View
26 activerecord/test/cases/associations/has_many_through_associations_test.rb
@@ -774,6 +774,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' }
@@ -782,4 +790,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 559d809

Please sign in to comment.