diff options
-rw-r--r-- | activerecord/CHANGELOG | 2 | ||||
-rwxr-xr-x | activerecord/lib/active_record/validations.rb | 1 | ||||
-rwxr-xr-x | activerecord/test/validations_test.rb | 6 |
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 |