diff options
author | Sean Griffin <sean@thoughtbot.com> | 2014-05-30 09:29:22 -0700 |
---|---|---|
committer | Sean Griffin <sean@thoughtbot.com> | 2014-06-01 11:33:58 -0600 |
commit | 90c8be76a7d00475be5ff4db2eeedde5cc936c2d (patch) | |
tree | 1b02b3ccffbef9296aaa6660caed5c64fcb362aa /activerecord/test | |
parent | 260c384bdb539265b31d3937df48e528acb50800 (diff) | |
download | rails-90c8be76a7d00475be5ff4db2eeedde5cc936c2d.tar.gz rails-90c8be76a7d00475be5ff4db2eeedde5cc936c2d.tar.bz2 rails-90c8be76a7d00475be5ff4db2eeedde5cc936c2d.zip |
Remove most code related to serialized properties
Nearly completely implemented in terms of custom properties.
`_before_type_cast` now stores the raw serialized string consistently,
which removes the need to keep track of "state". The following is now
consistently true:
- `model.serialized == model.reload.serialized`
- A model can be dumped and loaded infinitely without changing
- A model can be saved and reloaded infinitely without changing
Diffstat (limited to 'activerecord/test')
-rw-r--r-- | activerecord/test/cases/adapters/postgresql/composite_test.rb | 1 | ||||
-rw-r--r-- | activerecord/test/cases/attribute_methods_test.rb | 2 | ||||
-rw-r--r-- | activerecord/test/cases/serialized_attribute_test.rb | 11 |
3 files changed, 9 insertions, 5 deletions
diff --git a/activerecord/test/cases/adapters/postgresql/composite_test.rb b/activerecord/test/cases/adapters/postgresql/composite_test.rb index ecccbf10e6..d804d1fa97 100644 --- a/activerecord/test/cases/adapters/postgresql/composite_test.rb +++ b/activerecord/test/cases/adapters/postgresql/composite_test.rb @@ -93,6 +93,7 @@ class PostgresqlCompositeWithCustomOIDTest < ActiveRecord::TestCase end def type_cast_for_write(value) + return if value.nil? "(#{value.city},#{value.street})" end end diff --git a/activerecord/test/cases/attribute_methods_test.rb b/activerecord/test/cases/attribute_methods_test.rb index da2876170e..139fe9c04b 100644 --- a/activerecord/test/cases/attribute_methods_test.rb +++ b/activerecord/test/cases/attribute_methods_test.rb @@ -870,7 +870,7 @@ class AttributeMethodsTest < ActiveRecord::TestCase end def cached_columns - Topic.columns.map(&:name) - Topic.serialized_attributes.keys + Topic.columns.map(&:name) end def time_related_columns_on_topic diff --git a/activerecord/test/cases/serialized_attribute_test.rb b/activerecord/test/cases/serialized_attribute_test.rb index eaa28148f4..5ea62c9f59 100644 --- a/activerecord/test/cases/serialized_attribute_test.rb +++ b/activerecord/test/cases/serialized_attribute_test.rb @@ -59,8 +59,9 @@ class SerializedAttributeTest < ActiveRecord::TestCase def test_serialized_attribute_calling_dup_method Topic.serialize :content, JSON - t = Topic.new(:content => { :foo => :bar }).dup - assert_equal({ :foo => :bar }, t.content_before_type_cast) + orig = Topic.new(content: { foo: :bar }) + clone = orig.dup + assert_equal(orig.content, clone.content) end def test_serialized_attribute_declared_in_subclass @@ -103,8 +104,10 @@ class SerializedAttributeTest < ActiveRecord::TestCase def test_serialized_attribute_should_raise_exception_on_save_with_wrong_type Topic.serialize(:content, Hash) - topic = Topic.new(:content => "string") - assert_raise(ActiveRecord::SerializationTypeMismatch) { topic.save } + assert_raise(ActiveRecord::SerializationTypeMismatch) do + topic = Topic.new(content: 'string') + topic.save + end end def test_should_raise_exception_on_serialized_attribute_with_type_mismatch |