Skip to content

Commit 786342e

Browse files
David Trasbojosevalim
authored andcommitted
Return from ActiveRecord::Base#attributes= unless value is a hash [#4070 state:committed]
Signed-off-by: José Valim <jose.valim@gmail.com>
1 parent 1e53404 commit 786342e

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

activerecord/lib/active_record/base.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1471,7 +1471,7 @@ def []=(attr_name, value)
14711471
# user.send(:attributes=, { :username => 'Phusion', :is_admin => true }, false)
14721472
# user.is_admin? # => true
14731473
def attributes=(new_attributes, guard_protected_attributes = true)
1474-
return if new_attributes.nil?
1474+
return unless new_attributes.is_a? Hash
14751475
attributes = new_attributes.stringify_keys
14761476

14771477
multi_parameter_attributes = []

activerecord/test/cases/base_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ def test_set_attributes
6161
assert_equal(topics(:first).author_email_address, Topic.find(1).author_email_address)
6262
end
6363

64+
def test_set_attributes_without_hash
65+
topic = Topic.new
66+
assert_nothing_raised do
67+
topic.attributes = ''
68+
end
69+
end
70+
6471
def test_integers_as_nil
6572
test = AutoId.create('value' => '')
6673
assert_nil AutoId.find(test.id).value

0 commit comments

Comments
 (0)