@@ -5,6 +5,11 @@ class Serializer
55 module Adapter
66 class JsonApi
77 class ResourceTypeConfigTest < Minitest ::Test
8+ class ProfileTypeSerializer < ActiveModel ::Serializer
9+ attributes :name
10+ type 'profile'
11+ end
12+
813 def setup
914 @author = Author . new ( id : 1 , name : 'Steve K.' )
1015 @author . bio = nil
@@ -36,22 +41,29 @@ def with_jsonapi_resource_type type
3641 end
3742
3843 def test_config_plural
39- with_adapter :json_api do
40- with_jsonapi_resource_type :plural do
41- hash = ActiveModel ::SerializableResource . new ( @comment ) . serializable_hash
42- assert_equal ( 'comments' , hash [ :data ] [ :type ] )
43- end
44+ with_jsonapi_resource_type :plural do
45+ hash = serializable ( @comment , adapter : :json_api ) . serializable_hash
46+ assert_equal ( 'comments' , hash [ :data ] [ :type ] )
4447 end
4548 end
4649
4750 def test_config_singular
48- with_adapter :json_api do
49- with_jsonapi_resource_type :singular do
50- hash = ActiveModel ::SerializableResource . new ( @comment ) . serializable_hash
51- assert_equal ( 'comment' , hash [ :data ] [ :type ] )
52- end
51+ with_jsonapi_resource_type :singular do
52+ hash = serializable ( @comment , adapter : :json_api ) . serializable_hash
53+ assert_equal ( 'comment' , hash [ :data ] [ :type ] )
5354 end
5455 end
56+
57+ def test_explicit_type_value
58+ hash = serializable ( @author , serializer : ProfileTypeSerializer , adapter : :json_api ) . serializable_hash
59+ assert_equal ( 'profile' , hash . fetch ( :data ) . fetch ( :type ) )
60+ end
61+
62+ private
63+
64+ def serializable ( resource , options = { } )
65+ ActiveModel ::SerializableResource . new ( resource , options )
66+ end
5567 end
5668 end
5769 end
0 commit comments