Permalink
Browse files

Merge pull request #6676 from aurelian/master

Don't assign the attributes if the list is empty
  • Loading branch information...
2 parents fa4b029 + 79c8c4f commit a268d2dc972c73b9f406002364b633afa0d3d98c @rafaelfranca rafaelfranca committed Jun 12, 2012
@@ -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 = []
@@ -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)

0 comments on commit a268d2d

Please sign in to comment.