Skip to content

Commit

Permalink
Return from ActiveRecord::Base#attributes= unless value is a hash [#4070
Browse files Browse the repository at this point in the history
 state:committed]

Signed-off-by: José Valim <jose.valim@gmail.com>
  • Loading branch information
David Trasbo authored and josevalim committed Jul 8, 2010
1 parent 1e53404 commit 786342e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion activerecord/lib/active_record/base.rb
Expand Up @@ -1471,7 +1471,7 @@ def []=(attr_name, value)
# 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 = []
Expand Down
7 changes: 7 additions & 0 deletions activerecord/test/cases/base_test.rb
Expand Up @@ -61,6 +61,13 @@ def test_set_attributes
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
Expand Down

2 comments on commit 786342e

@dmitry
Copy link
Contributor

@dmitry dmitry commented on 786342e Jul 9, 2010

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this feature is only for the ActiveResource?

@dtrasbo
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually it used to be an Active Record specific bug.

Please sign in to comment.