From 75ffd8701d04d943eddcafee08e19b90bce8936c Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Tue, 7 Feb 2012 23:23:18 +0000 Subject: Fix attribute_before_type_cast for serialized attributes. Fixes #4837. --- activerecord/test/cases/base_test.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'activerecord/test/cases/base_test.rb') diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index d70525b57d..dfa05990f9 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -1279,6 +1279,21 @@ class BasicsTest < ActiveRecord::TestCase assert_equal(hash, important_topic.content) end + # This test was added to fix GH #4004. Obviously the value returned + # is not really the value 'before type cast' so we should maybe think + # about changing that in the future. + def test_serialized_attribute_before_type_cast_returns_unserialized_value + klass = Class.new(ActiveRecord::Base) + klass.table_name = "topics" + klass.serialize :content, Hash + + t = klass.new(:content => { :foo => :bar }) + assert_equal({ :foo => :bar }, t.content_before_type_cast) + t.save! + t.reload + assert_equal({ :foo => :bar }, t.content_before_type_cast) + end + def test_serialized_attribute_declared_in_subclass hash = { 'important1' => 'value1', 'important2' => 'value2' } important_topic = ImportantTopic.create("important" => hash) -- cgit v1.2.3