aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/test/cases/attribute_methods/serialization_test.rb
blob: 8ce6192096e41a9d16bc2b63e004c49fd1413b70 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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