mirror of
https://github.com/github/rails.git
synced 2026-01-30 00:38:00 -05:00
Make sure create! raises errors on validation when creating multiple records. [hasmanyjosh] Closes #8952
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@7361 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
@@ -850,7 +850,7 @@ module ActiveRecord
|
||||
# so an exception is raised if the record is invalid.
|
||||
def create!(attributes = nil)
|
||||
if attributes.is_a?(Array)
|
||||
attributes.collect { |attr| create(attr) }
|
||||
attributes.collect { |attr| create!(attr) }
|
||||
else
|
||||
object = new(attributes)
|
||||
object.save!
|
||||
|
||||
@@ -95,6 +95,12 @@ class ValidationsTest < Test::Unit::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
def test_exception_on_create_bang_many
|
||||
assert_raises(ActiveRecord::RecordInvalid) do
|
||||
Reply.create!([ { "title" => "OK" }, { "title" => "Wrong Create" }])
|
||||
end
|
||||
end
|
||||
|
||||
def test_scoped_create_without_attributes
|
||||
Reply.with_scope(:create => {}) do
|
||||
assert_raises(ActiveRecord::RecordInvalid) { Reply.create! }
|
||||
|
||||
Reference in New Issue
Block a user