Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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

…t have validation errors
  • Loading branch information...
commit 559d809609570466ea1f86b0255e0269b43a2a3b 1 parent 9643387
@tenderlove tenderlove authored
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
Please sign in to comment.
Something went wrong with that request. Please try again.