Skip to content

Commit

Permalink
create! no longer blows up when no attributes are passed and a :creat…
Browse files Browse the repository at this point in the history
…e scope is in effect (e.g. foo.bars.create! failed whereas foo.bars.create!({}) didn't.)

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4348 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
jeremy committed May 19, 2006
1 parent 0cd883e commit c50113b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions activerecord/CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
*SVN*

* create! no longer blows up when no attributes are passed and a :create scope is in effect (e.g. foo.bars.create! failed whereas foo.bars.create!({}) didn't.) [Jeremy Kemper]

* Call Inflector#demodulize on the class name when eagerly including an STI model. Closes #5077 [info@loobmedia.com]

* Preserve MySQL boolean column defaults when changing a column in a migration. Closes #5015. [pdcawley@bofh.org.uk]
Expand Down
1 change: 1 addition & 0 deletions activerecord/lib/active_record/validations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,7 @@ def create!(attributes = nil)
if attributes.is_a?(Array)
attributes.collect { |attr| create!(attr) }
else
attributes ||= {}
attributes.reverse_merge!(scope(:create)) if scoped?(:create)

object = new(attributes)
Expand Down
6 changes: 6 additions & 0 deletions activerecord/test/validations_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ def test_invalid_record_exception
end
end

def test_scoped_create_without_attributes
Reply.with_scope(:create => {}) do
assert_raises(ActiveRecord::RecordInvalid) { Reply.create! }
end
end

def test_single_error_per_attr_iteration
r = Reply.new
r.save
Expand Down

0 comments on commit c50113b

Please sign in to comment.