diff --git a/activerecord/CHANGELOG b/activerecord/CHANGELOG index c012f0d131b4762dd6ff31d2a0252d4c092e6bba..1e351913b17625ca97bbf1162edb06313894f441 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 4194e68b2f35e9ed759c628ac16625e824053537..29c2b79226ed12fd11ea9c521b1cc7d9c6521a3c 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 6ef455459b25d6c1c4c724bd1b2275bc3e73df20..c84408b1b85c0dfb5c5e15b7b6f5e9749f92d67b 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