diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index cb74a01388d40..c78060c956872 100644 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -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 = [] diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index 09bdd13cd4fcc..a4cf5120e14bc 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -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