mirror of
https://github.com/github/rails.git
synced 2026-04-26 03:00:59 -04:00
Return from ActiveRecord::Base#attributes= unless value is a hash [#4070 state:committed]
Signed-off-by: José Valim <jose.valim@gmail.com>
This commit is contained in:
@@ -1471,7 +1471,7 @@ MSG
|
||||
# user.send(:attributes=, { :username => 'Phusion', :is_admin => true }, false)
|
||||
# user.is_admin? # => true
|
||||
def attributes=(new_attributes, guard_protected_attributes = true)
|
||||
return if new_attributes.nil?
|
||||
return unless new_attributes.is_a? Hash
|
||||
attributes = new_attributes.stringify_keys
|
||||
|
||||
multi_parameter_attributes = []
|
||||
|
||||
@@ -61,6 +61,13 @@ class BasicsTest < ActiveRecord::TestCase
|
||||
assert_equal(topics(:first).author_email_address, Topic.find(1).author_email_address)
|
||||
end
|
||||
|
||||
def test_set_attributes_without_hash
|
||||
topic = Topic.new
|
||||
assert_nothing_raised do
|
||||
topic.attributes = ''
|
||||
end
|
||||
end
|
||||
|
||||
def test_integers_as_nil
|
||||
test = AutoId.create('value' => '')
|
||||
assert_nil AutoId.find(test.id).value
|
||||
|
||||
Reference in New Issue
Block a user