提交 559d8096 编写于 作者: A Aaron Patterson

add tests surrounding behavior of save and save! for associations that have validation errors

上级 96433877
......@@ -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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册