aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorDavid Trasbo <me@dtrasbo.com>2010-06-30 21:33:49 +0200
committerJosé Valim <jose.valim@gmail.com>2010-07-08 23:24:20 +0200
commit786342e17f42799ef889cf6127fe97e9598272e0 (patch)
tree0e0d539db6000d2d7510cf9691bbe42681661684 /activerecord
parent1e53404fe9c39ad0849894d73e431315be8c0bf0 (diff)
downloadrails-786342e17f42799ef889cf6127fe97e9598272e0.tar.gz
rails-786342e17f42799ef889cf6127fe97e9598272e0.tar.bz2
rails-786342e17f42799ef889cf6127fe97e9598272e0.zip
Return from ActiveRecord::Base#attributes= unless value is a hash [#4070 state:committed]
Signed-off-by: José Valim <jose.valim@gmail.com>
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/base.rb2
-rw-r--r--activerecord/test/cases/base_test.rb7
2 files changed, 8 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index cb74a01388..c78060c956 100644
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -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 = []
diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb
index 09bdd13cd4..a4cf5120e1 100644
--- a/activerecord/test/cases/base_test.rb
+++ b/activerecord/test/cases/base_test.rb
@@ -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