diff options
author | Guillermo Álvarez <guillermo@cientifico.net> | 2011-02-03 00:26:39 +0100 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-02-03 09:08:45 -0800 |
commit | 351331fb343cdf17baa078943898ded6caff9d65 (patch) | |
tree | 8b57684788395cbe899a27c24f51a990eb416584 /activerecord/test/cases | |
parent | 080345baca1076a9788dff4803153600aec31f86 (diff) | |
download | rails-351331fb343cdf17baa078943898ded6caff9d65.tar.gz rails-351331fb343cdf17baa078943898ded6caff9d65.tar.bz2 rails-351331fb343cdf17baa078943898ded6caff9d65.zip |
Make serialized columns with explicit object_type return a new instance of the object instead of nil
Diffstat (limited to 'activerecord/test/cases')
-rw-r--r-- | activerecord/test/cases/base_test.rb | 19 | ||||
-rw-r--r-- | activerecord/test/cases/coders/yaml_column_test.rb | 5 |
2 files changed, 22 insertions, 2 deletions
diff --git a/activerecord/test/cases/base_test.rb b/activerecord/test/cases/base_test.rb index 5cbc52732b..a255c07957 100644 --- a/activerecord/test/cases/base_test.rb +++ b/activerecord/test/cases/base_test.rb @@ -1002,6 +1002,25 @@ class BasicsTest < ActiveRecord::TestCase Topic.serialize(:content) end + def test_serialized_default_class + Topic.serialize(:content, Hash) + topic = Topic.new + assert_equal Hash, topic.content.class + assert_equal Hash, topic.read_attribute(:content).class + topic.content["beer"] = "MadridRb" + assert topic.save + topic.reload + assert_equal Hash, topic.content.class + assert_equal "MadridRb", topic.content["beer"] + ensure + Topic.serialize(:content) + end + + def test_serialized_no_default_class_for_object + topic = Topic.new + assert_nil topic.content + end + def test_serialized_boolean_value_true Topic.serialize(:content) topic = Topic.new(:content => true) diff --git a/activerecord/test/cases/coders/yaml_column_test.rb b/activerecord/test/cases/coders/yaml_column_test.rb index f85f11b57f..c7dcc21809 100644 --- a/activerecord/test/cases/coders/yaml_column_test.rb +++ b/activerecord/test/cases/coders/yaml_column_test.rb @@ -1,3 +1,4 @@ + require "cases/helper" module ActiveRecord @@ -20,9 +21,9 @@ module ActiveRecord assert_nil coder.load "--- " end - def test_nil_is_ok_with_different_class + def test_returns_new_with_different_class coder = YAMLColumn.new SerializationTypeMismatch - assert_nil coder.load "--- " + assert_equal SerializationTypeMismatch, coder.load("--- ").class end def test_returns_string_unless_starts_with_dash |