diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-06-12 10:45:19 -0700 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-06-12 14:47:52 -0300 |
commit | 32709ea41ed1ec2a89590e9bc6656c1ecd462d30 (patch) | |
tree | 8df23958c88580d8f0ae5b17b4567419645a4ad9 | |
parent | 6522a127e549040d834196eea6eb2818e5051dba (diff) | |
download | rails-32709ea41ed1ec2a89590e9bc6656c1ecd462d30.tar.gz rails-32709ea41ed1ec2a89590e9bc6656c1ecd462d30.tar.bz2 rails-32709ea41ed1ec2a89590e9bc6656c1ecd462d30.zip |
Merge pull request #6676 from aurelian/master
Don't assign the attributes if the list is empty
-rw-r--r-- | activerecord/lib/active_record/attribute_assignment.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/mass_assignment_security_test.rb | 4 |
2 files changed, 5 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/attribute_assignment.rb b/activerecord/lib/active_record/attribute_assignment.rb index bf9fe70b31..ca5f7b9c6c 100644 --- a/activerecord/lib/active_record/attribute_assignment.rb +++ b/activerecord/lib/active_record/attribute_assignment.rb @@ -64,7 +64,7 @@ module ActiveRecord # user.name # => "Josh" # user.is_admin? # => true def assign_attributes(new_attributes, options = {}) - return unless new_attributes + return if new_attributes.blank? attributes = new_attributes.stringify_keys multi_parameter_attributes = [] diff --git a/activerecord/test/cases/mass_assignment_security_test.rb b/activerecord/test/cases/mass_assignment_security_test.rb index 8122857f52..e47b06f244 100644 --- a/activerecord/test/cases/mass_assignment_security_test.rb +++ b/activerecord/test/cases/mass_assignment_security_test.rb @@ -98,6 +98,10 @@ class MassAssignmentSecurityTest < ActiveRecord::TestCase Firm.new.assign_attributes(nil) end + def test_mass_assigning_does_not_choke_on_empty_hash + Firm.new.assign_attributes({}) + end + def test_assign_attributes_uses_default_role_when_no_role_is_provided p = LoosePerson.new p.assign_attributes(attributes_hash) |