@@ -141,7 +141,7 @@ def as_jsonapi(options = {})
141141 end
142142
143143 it 'renders nil' do
144- actual = JSONAPI . render ( nil )
144+ actual = JSONAPI . render ( data : nil )
145145 expected = {
146146 data : nil
147147 }
@@ -150,7 +150,7 @@ def as_jsonapi(options = {})
150150 end
151151
152152 it 'renders an empty array' do
153- actual = JSONAPI . render ( [ ] )
153+ actual = JSONAPI . render ( data : [ ] )
154154 expected = {
155155 data : [ ]
156156 }
@@ -159,7 +159,7 @@ def as_jsonapi(options = {})
159159 end
160160
161161 it 'renders a single resource' do
162- actual = JSONAPI . render ( UserResource . new ( @users [ 0 ] ) )
162+ actual = JSONAPI . render ( data : UserResource . new ( @users [ 0 ] ) )
163163 expected = {
164164 data : {
165165 type : 'users' ,
@@ -197,8 +197,8 @@ def as_jsonapi(options = {})
197197 end
198198
199199 it 'renders a collection of resources' do
200- actual = JSONAPI . render ( [ UserResource . new ( @users [ 0 ] ) ,
201- UserResource . new ( @users [ 1 ] ) ] )
200+ actual = JSONAPI . render ( data : [ UserResource . new ( @users [ 0 ] ) ,
201+ UserResource . new ( @users [ 1 ] ) ] )
202202 expected = {
203203 data : [
204204 {
@@ -268,7 +268,7 @@ def as_jsonapi(options = {})
268268 end
269269
270270 it 'renders included relationships' do
271- actual = JSONAPI . render ( UserResource . new ( @users [ 0 ] ) ,
271+ actual = JSONAPI . render ( data : UserResource . new ( @users [ 0 ] ) ,
272272 include : 'posts' )
273273 expected = {
274274 data : {
@@ -329,7 +329,7 @@ def as_jsonapi(options = {})
329329 end
330330
331331 it 'filters out fields' do
332- actual = JSONAPI . render ( UserResource . new ( @users [ 0 ] ) ,
332+ actual = JSONAPI . render ( data : UserResource . new ( @users [ 0 ] ) ,
333333 fields : { users : [ :name ] } )
334334 expected = {
335335 data : {
@@ -351,7 +351,7 @@ def as_jsonapi(options = {})
351351 end
352352
353353 it 'renders a toplevel meta' do
354- actual = JSONAPI . render ( nil ,
354+ actual = JSONAPI . render ( data : nil ,
355355 meta : { this : 'is_meta' } )
356356 expected = {
357357 data : nil ,
@@ -362,7 +362,7 @@ def as_jsonapi(options = {})
362362 end
363363
364364 it 'renders toplevel links' do
365- actual = JSONAPI . render ( nil ,
365+ actual = JSONAPI . render ( data : nil ,
366366 links : { self : 'http://api.example.com/users' } )
367367 expected = {
368368 data : nil ,
@@ -373,8 +373,8 @@ def as_jsonapi(options = {})
373373 end
374374
375375 it 'renders a toplevel jsonapi object' do
376- actual = JSONAPI . render ( nil ,
377- jsonapi_object : {
376+ actual = JSONAPI . render ( data : nil ,
377+ jsonapi : {
378378 version : '1.0' ,
379379 meta : 'For real'
380380 } )
@@ -388,4 +388,11 @@ def as_jsonapi(options = {})
388388
389389 expect ( actual ) . to eq ( expected )
390390 end
391+
392+ it 'renders an empty hash if neither errors nor data provided' do
393+ actual = JSONAPI . render ( { } )
394+ expected = { }
395+
396+ expect ( actual ) . to eq ( expected )
397+ end
391398end
0 commit comments