aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/test/cases/attribute_methods/serialization_test.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/activerecord/test/cases/attribute_methods/serialization_test.rb b/activerecord/test/cases/attribute_methods/serialization_test.rb
new file mode 100644
index 0000000000..8ce6192096
--- /dev/null
+++ b/activerecord/test/cases/attribute_methods/serialization_test.rb
@@ -0,0 +1,28 @@
+require "cases/helper"
+
+module ActiveRecord
+ module AttributeMethods
+ class SerializationTest < ActiveSupport::TestCase
+ class FakeColumn < Struct.new(:name)
+ def type; :integer; end
+ def type_cast(s); "#{s}!"; end
+ end
+
+ def test_type_cast_serialized_value
+ value = stub(state: :serialized, value: "Hello world")
+ value.expects(:unserialized_value).with("Hello world!")
+
+ type = Serialization::Type.new(FakeColumn.new)
+ type.type_cast(value)
+ end
+
+ def test_type_cast_unserialized_value
+ value = stub(state: :unserialized, value: "Hello world")
+ value.expects(:unserialized_value).with()
+
+ type = Serialization::Type.new(FakeColumn.new)
+ type.type_cast(value)
+ end
+ end
+ end
+end