Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #6676 from aurelian/master

Don't assign the attributes if the list is empty
  • Loading branch information...
commit 32709ea41ed1ec2a89590e9bc6656c1ecd462d30 1 parent 6522a12
@rafaelfranca rafaelfranca authored
View
2  activerecord/lib/active_record/attribute_assignment.rb
@@ -64,7 +64,7 @@ def attributes=(new_attributes)
# 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 = []
View
4 activerecord/test/cases/mass_assignment_security_test.rb
@@ -98,6 +98,10 @@ def test_mass_assigning_does_not_choke_on_nil
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)
Please sign in to comment.
Something went wrong with that request. Please try again.