diff options
-rwxr-xr-x | activerecord/lib/active_record/base.rb | 5 | ||||
-rwxr-xr-x | activerecord/test/base_test.rb | 15 |
2 files changed, 16 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index dc3dc2afa6..00f98d51d3 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -1334,8 +1334,9 @@ module ActiveRecord #:nodoc: # from this form of mass-assignment by using the +attr_protected+ macro. Or you can alternatively # specify which attributes *can* be accessed in with the +attr_accessible+ macro. Then all the # attributes not included in that won't be allowed to be mass-assigned. - def attributes=(attributes) - return if attributes.nil? + def attributes=(attrs) + return if attrs.nil? + attributes= attrs.dup attributes.stringify_keys! multi_parameter_attributes = [] diff --git a/activerecord/test/base_test.rb b/activerecord/test/base_test.rb index 9b5d053a98..4de720a176 100755 --- a/activerecord/test/base_test.rb +++ b/activerecord/test/base_test.rb @@ -133,8 +133,19 @@ class BasicsTest < Test::Unit::TestCase topic = Topic.new topic.title = "New Topic" topic.save - topicReloaded = Topic.find(topic.id) - assert_equal("New Topic", topicReloaded.title) + topic_reloaded = Topic.find(topic.id) + assert_equal("New Topic", topic_reloaded.title) + end + + def test_hashes_not_mangled + new_topic = { :title => "New Topic" } + new_topic_values = { :title => "AnotherTopic" } + + topic = Topic.new(new_topic) + assert_equal new_topic[:title], topic.title + + topic.attributes= new_topic_values + assert_equal new_topic_value[:title], topic.title end def test_create_many |