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.)

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@4348 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
Jeremy Kemper 2006-05-19 01:05:20 +00:00
parent 0cd883e1e1
commit c50113bc61
3 changed files with 9 additions and 0 deletions

View File

@ -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]

View File

@ -712,6 +712,7 @@ module ActiveRecord
if attributes.is_a?(Array)
attributes.collect { |attr| create!(attr) }
else
attributes ||= {}
attributes.reverse_merge!(scope(:create)) if scoped?(:create)
object = new(attributes)

View File

@ -88,6 +88,12 @@ class ValidationsTest < Test::Unit::TestCase
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