Browse files

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
  • Loading branch information...
1 parent 5f163d2 commit 016947ceedfb43a864ea4ef57d97366ab2825785 @NZKoz NZKoz committed Aug 28, 2007
Showing with 7 additions and 1 deletion.
  1. +1 −1 activerecord/lib/active_record/validations.rb
  2. +6 −0 activerecord/test/validations_test.rb
View
2 activerecord/lib/active_record/validations.rb
@@ -850,7 +850,7 @@ def validates_numericality_of(*attr_names)
# 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!
View
6 activerecord/test/validations_test.rb
@@ -95,6 +95,12 @@ def test_invalid_record_exception
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! }

0 comments on commit 016947c

Please sign in to comment.