From 6891790fb192d6ab1bdb9e054ef9f5ab8b95bfc7 Mon Sep 17 00:00:00 2001 From: Tom Lea Date: Mon, 11 Aug 2008 18:16:58 +0100 Subject: [PATCH] Serialized attributes will now always be saved even with partial_updates turned on. --- activerecord/lib/active_record/dirty.rb | 2 +- activerecord/test/cases/dirty_test.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletions(-) diff --git a/activerecord/lib/active_record/dirty.rb b/activerecord/lib/active_record/dirty.rb index 4ce0356..dc96866 100644 --- a/activerecord/lib/active_record/dirty.rb +++ b/activerecord/lib/active_record/dirty.rb @@ -134,7 +134,7 @@ module ActiveRecord def update_with_dirty if partial_updates? - update_without_dirty(changed) + update_without_dirty(changed | self.class.serialized_attributes.keys) else update_without_dirty end diff --git a/activerecord/test/cases/dirty_test.rb b/activerecord/test/cases/dirty_test.rb index e5e0220..feb47a1 100644 --- a/activerecord/test/cases/dirty_test.rb +++ b/activerecord/test/cases/dirty_test.rb @@ -191,6 +191,18 @@ class DirtyTest < ActiveRecord::TestCase assert !pirate.changed? end + def test_save_should_store_serialized_attributes_even_with_partial_updates + with_partial_updates(Topic) do + topic = Topic.create!(:content => {:a => "a"}) + topic.content[:b] = "b" + #assert topic.changed? # Known bug, will fail + topic.save! + assert_equal "b", topic.content[:b] + topic.reload + assert_equal "b", topic.content[:b] + end + end + private def with_partial_updates(klass, on = true) old = klass.partial_updates? -- 1.5.2.4