diff options
Diffstat (limited to 'activerecord')
-rw-r--r-- | activerecord/CHANGELOG.md | 11 | ||||
-rw-r--r-- | activerecord/lib/active_record/relation.rb | 4 | ||||
-rw-r--r-- | activerecord/test/cases/relations_test.rb | 4 |
3 files changed, 11 insertions, 8 deletions
diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 7a549397a0..faf1bbf232 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,5 +1,9 @@ ## Rails 4.0.0 (unreleased) ## +* Raise `ArgumentError` if list of attributes to change is empty in `update_all`. + + *Roman Shatsov* + * Fix AR#create to return an unsaved record when AR::RecordInvalid is raised. Fixes #3217. @@ -586,7 +590,6 @@ * PostgreSQL hstore types are automatically deserialized from the database. - ## Rails 3.2.8 (Aug 9, 2012) ## * Do not consider the numeric attribute as changed if the old value is zero and the new value @@ -595,12 +598,6 @@ *Rafael Mendonça França* -* Do not consider the numeric attribute as changed if the old value is zero and the new value - is not a string. - Fixes #7237. - - *Rafael Mendonça França* - * Removes the deprecation of `update_attribute`. *fxn* * Reverted the deprecation of `composed_of`. *Rafael Mendonça França* diff --git a/activerecord/lib/active_record/relation.rb b/activerecord/lib/active_record/relation.rb index 9ed3256ae9..1abbc58314 100644 --- a/activerecord/lib/active_record/relation.rb +++ b/activerecord/lib/active_record/relation.rb @@ -258,6 +258,8 @@ module ActiveRecord # # Update all books that match conditions, but limit it to 5 ordered by date # Book.where('title LIKE ?', '%Rails%').order(:created_at).limit(5).update_all(:author => 'David') def update_all(updates) + raise ArgumentError, "Empty list of attributes to change" if updates.blank? + stmt = Arel::UpdateManager.new(arel.engine) stmt.set Arel.sql(@klass.send(:sanitize_sql_for_assignment, updates)) @@ -466,7 +468,7 @@ module ActiveRecord # Returns sql statement for the relation. # # Users.where(name: 'Oscar').to_sql - # # => SELECT "users".* FROM "users" WHERE "users"."name" = 'Oscar' + # # => SELECT "users".* FROM "users" WHERE "users"."name" = 'Oscar' def to_sql @to_sql ||= klass.connection.to_sql(arel, bind_values.dup) end diff --git a/activerecord/test/cases/relations_test.rb b/activerecord/test/cases/relations_test.rb index 0bd48913e1..84027ea5ae 100644 --- a/activerecord/test/cases/relations_test.rb +++ b/activerecord/test/cases/relations_test.rb @@ -1122,6 +1122,10 @@ class RelationTest < ActiveRecord::TestCase assert_equal authors(:david), Author.order('id DESC , name DESC').last end + def test_update_all_with_blank_argument + assert_raises(ArgumentError) { Comment.update_all({}) } + end + def test_update_all_with_joins comments = Comment.joins(:post).where('posts.id' => posts(:welcome).id) count = comments.count |