From c50113bc6110624bd411466e7c36bdde23226959 Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Fri, 19 May 2006 01:05:20 +0000 Subject: [PATCH] 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 --- activerecord/CHANGELOG | 2 ++ activerecord/lib/active_record/validations.rb | 1 + activerecord/test/validations_test.rb | 6 ++++++ 3 files changed, 9 insertions(+) diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index c012f0d131..1e351913b1 100644 --- a/activerecord/CHANGELOG +++ b/activerecord/CHANGELOG @@ -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] diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb index 4194e68b2f..29c2b79226 100755 --- a/activerecord/lib/active_record/validations.rb +++ b/activerecord/lib/active_record/validations.rb @@ -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) diff --git a/activerecord/test/validations_test.rb b/activerecord/test/validations_test.rb index 6ef455459b..c84408b1b8 100755 --- a/activerecord/test/validations_test.rb +++ b/activerecord/test/validations_test.rb @@ -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 -- GitLab