Skip to content
This repository
Browse code

Don't alter the Hash passed to attributes=, closes #3385

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3417 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
commit f41feb349caed7580ba0493e3bb2e393cdb45ddb 1 parent f9e0ba2
Michael Koziarski authored
5  activerecord/lib/active_record/base.rb
@@ -1334,8 +1334,9 @@ def []=(attr_name, value)
1334 1334
       # from this form of mass-assignment by using the +attr_protected+ macro. Or you can alternatively
1335 1335
       # specify which attributes *can* be accessed in with the +attr_accessible+ macro. Then all the
1336 1336
       # attributes not included in that won't be allowed to be mass-assigned.
1337  
-      def attributes=(attributes)
1338  
-        return if attributes.nil?
  1337
+      def attributes=(attrs)
  1338
+        return if attrs.nil?
  1339
+        attributes= attrs.dup
1339 1340
         attributes.stringify_keys!
1340 1341
 
1341 1342
         multi_parameter_attributes = []
15  activerecord/test/base_test.rb
@@ -133,8 +133,19 @@ def test_create
133 133
     topic = Topic.new
134 134
     topic.title = "New Topic"
135 135
     topic.save
136  
-    topicReloaded = Topic.find(topic.id)
137  
-    assert_equal("New Topic", topicReloaded.title)
  136
+    topic_reloaded = Topic.find(topic.id)
  137
+    assert_equal("New Topic", topic_reloaded.title)
  138
+  end
  139
+    
  140
+  def test_hashes_not_mangled
  141
+    new_topic = { :title => "New Topic" }
  142
+    new_topic_values = { :title => "AnotherTopic" }
  143
+
  144
+    topic = Topic.new(new_topic)
  145
+    assert_equal new_topic[:title], topic.title
  146
+
  147
+    topic.attributes= new_topic_values
  148
+    assert_equal new_topic_value[:title], topic.title
138 149
   end
139 150
   
140 151
   def test_create_many

0 notes on commit f41feb3

Please sign in to comment.
Something went wrong with that request. Please try again.