aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2012-02-07 23:23:18 +0000
committerJon Leighton <j@jonathanleighton.com>2012-02-07 23:41:21 +0000
commit77b4edce1544f105cc7764249becc1e998b88fc2 (patch)
tree8e5b3a1a70220ea7abbb3f05e8fccb5abbafb5e3 /activerecord/test
parentb3328779d0ce8e4568e7966099754eae1e5791ad (diff)
downloadrails-77b4edce1544f105cc7764249becc1e998b88fc2.tar.gz
rails-77b4edce1544f105cc7764249becc1e998b88fc2.tar.bz2
rails-77b4edce1544f105cc7764249becc1e998b88fc2.zip
Fix attribute_before_type_cast for serialized attributes. Fixes #4837.
Conflicts: activerecord/lib/active_record/core.rb
Diffstat (limited to 'activerecord/test')
-rw-r--r--activerecord/test/cases/base_test.rb15
1 files changed, 15 insertions, 0 deletions
diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb
index 703bb7eb5c..aeb44da2b2 100644
--- a/activerecord/test/cases/base_test.rb
+++ b/activerecord/test/cases/base_test.rb
@@ -1251,6 +1251,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)