aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2012-06-12 10:45:19 -0700
committerRafael Mendonça França <rafaelmfranca@gmail.com>2012-06-12 10:45:19 -0700
commita268d2dc972c73b9f406002364b633afa0d3d98c (patch)
tree5bbce63602924c8b3d301905167d0130b0aeaf89 /activerecord
parentfa4b0295b62c1ff60d28f267435bfa7d90db5b95 (diff)
parent79c8c4fed46775f30551f6d4b0c50b9ba397bc54 (diff)
downloadrails-a268d2dc972c73b9f406002364b633afa0d3d98c.tar.gz
rails-a268d2dc972c73b9f406002364b633afa0d3d98c.tar.bz2
rails-a268d2dc972c73b9f406002364b633afa0d3d98c.zip
Merge pull request #6676 from aurelian/master
Don't assign the attributes if the list is empty
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/attribute_assignment.rb2
-rw-r--r--activerecord/test/cases/mass_assignment_security_test.rb4
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 e0bf80142a..abc2fa546a 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 1b5421c25e..b35dc2d26d 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)