public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Serialized attributes will now always be saved even with partial_updates turned 
on.

Signed-off-by: Michael Koziarski <michael@koziarski.com>
[#788 state:committed]
Tom Lea (author)
Mon Aug 11 10:16:58 -0700 2008
NZKoz (committer)
Tue Aug 12 09:18:29 -0700 2008
commit  decc9730959de85b4c4873986bcd33e12fa1985d
tree    f9f33b32f3201ac01604670913166e552ac25565
parent  88eec8327b179cd41314e85868879b46bcf2530e
...
134
135
136
137
 
 
 
138
139
140
...
134
135
136
 
137
138
139
140
141
142
0
@@ -134,7 +134,9 @@ module ActiveRecord
0
 
0
       def update_with_dirty
0
         if partial_updates?
0
-          update_without_dirty(changed)
0
+          # Serialized attributes should always be written in case they've been
0
+          # changed in place.
0
+          update_without_dirty(changed | self.class.serialized_attributes.keys)
0
         else
0
           update_without_dirty
0
         end
...
191
192
193
 
 
 
 
 
 
 
 
 
 
 
 
194
195
196
...
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
0
@@ -191,6 +191,18 @@ class DirtyTest < ActiveRecord::TestCase
0
     assert !pirate.changed?
0
   end
0
 
0
+  def test_save_should_store_serialized_attributes_even_with_partial_updates
0
+    with_partial_updates(Topic) do
0
+      topic = Topic.create!(:content => {:a => "a"})
0
+      topic.content[:b] = "b"
0
+      #assert topic.changed? # Known bug, will fail
0
+      topic.save!
0
+      assert_equal "b", topic.content[:b]
0
+      topic.reload
0
+      assert_equal "b", topic.content[:b]
0
+    end
0
+  end
0
+
0
   private
0
     def with_partial_updates(klass, on = true)
0
       old = klass.partial_updates?

Comments