Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Ensure assign_attributes and update_attributes do not fail on nil, cl…

…oses #478.
  • Loading branch information...
commit 9e4b715d790aa84dfb3d7aa332e0012cbc264394 1 parent 86a0f7f
@josevalim josevalim authored
View
2  activerecord/lib/active_record/base.rb
@@ -1688,6 +1688,8 @@ def attributes=(new_attributes, guard_protected_attributes = nil)
# user.name # => "Josh"
# user.is_admin? # => true
def assign_attributes(new_attributes, options = {})
+ return unless new_attributes
+
attributes = new_attributes.stringify_keys
role = options[:as] || :default
View
4 activerecord/test/cases/mass_assignment_security_test.rb
@@ -87,6 +87,10 @@ def test_mass_assigning_invalid_attribute
end
end
+ def test_mass_assigning_does_not_choke_on_nil
+ Firm.new.assign_attributes(nil)
+ end
+
def test_assign_attributes_uses_default_role_when_no_role_is_provided
p = LoosePerson.new
p.assign_attributes(attributes_hash)
View
4 activerecord/test/cases/persistence_test.rb
@@ -336,6 +336,10 @@ def test_update_attribute
assert !Topic.find(1).approved?
end
+ def test_update_attribute_does_not_choke_on_nil
+ assert Topic.find(1).update_attributes(nil)
+ end
+
def test_update_attribute_for_readonly_attribute
minivan = Minivan.find('m1')
assert_raises(ActiveRecord::ActiveRecordError) { minivan.update_attribute(:color, 'black') }
Please sign in to comment.
Something went wrong with that request. Please try again.