@@ -95,35 +95,64 @@ def create
9595 end
9696 end
9797
98- describe '#render jsonapi:' do
99- controller do
100- def index
101- serializer = Class . new ( JSONAPI ::Serializable ::Resource ) do
102- type :users
103- attribute :name
98+ describe '#render' do
99+ context 'when calling render jsonapi: user' do
100+ controller do
101+ def index
102+ serializer = Class . new ( JSONAPI ::Serializable ::Resource ) do
103+ type :users
104+ attribute :name
105+ end
106+ user = OpenStruct . new ( id : 1 , name : 'Lucas' )
107+
108+ render jsonapi : user , class : serializer
104109 end
105- user = OpenStruct . new ( id : 1 , name : 'Lucas' )
110+ end
111+
112+ subject { JSON . parse ( response . body ) }
113+ let ( :serialized_user ) do
114+ {
115+ 'data' => {
116+ 'id' => '1' ,
117+ 'type' => 'users' ,
118+ 'attributes' => { 'name' => 'Lucas' }
119+ }
120+ }
121+ end
122+
123+ it 'renders a JSON API success document' do
124+ get :index
106125
107- render jsonapi : user , class : serializer
126+ expect ( response . content_type ) . to eq ( 'application/vnd.api+json' )
127+ is_expected . to eq ( serialized_user )
108128 end
109129 end
110130
111- subject { JSON . parse ( response . body ) }
112- let ( :serialized_user ) do
113- {
114- 'data' => {
115- 'id' => '1' ,
116- 'type' => 'users' ,
117- 'attributes' => { 'name' => 'Lucas' }
131+ context 'when specifying a default jsonapi object' do
132+ controller do
133+ def index
134+ render jsonapi : nil
135+ end
136+
137+ def jsonapi_object
138+ { version : '1.0' }
139+ end
140+ end
141+
142+ subject { JSON . parse ( response . body ) }
143+ let ( :document ) do
144+ {
145+ 'data' => nil ,
146+ 'jsonapi' => { 'version' => '1.0' }
118147 }
119- }
120- end
148+ end
121149
122- it 'renders a JSON API document' do
123- get :index
150+ it 'renders a JSON API success document' do
151+ get :index
124152
125- expect ( response . content_type ) . to eq ( 'application/vnd.api+json' )
126- is_expected . to eq ( serialized_user )
153+ expect ( response . content_type ) . to eq ( 'application/vnd.api+json' )
154+ is_expected . to eq ( document )
155+ end
127156 end
128157 end
129158end
0 commit comments