aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2006-05-19 01:05:20 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2006-05-19 01:05:20 +0000
commitc50113bc6110624bd411466e7c36bdde23226959 (patch)
tree15d9e6843c9f9b301b1b0c4b76dd551dc77910e5
parent0cd883e1e1752c92ba080850833c6989a057bf6c (diff)
downloadrails-c50113bc6110624bd411466e7c36bdde23226959.tar.gz
rails-c50113bc6110624bd411466e7c36bdde23226959.tar.bz2
rails-c50113bc6110624bd411466e7c36bdde23226959.zip
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
-rw-r--r--activerecord/CHANGELOG2
-rwxr-xr-xactiverecord/lib/active_record/validations.rb1
-rwxr-xr-xactiverecord/test/validations_test.rb6
3 files changed, 9 insertions, 0 deletions
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 @@ 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)
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 @@ 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