@@ -349,11 +349,27 @@ class BlahSerializer
349349 expect ( serializable_hash [ 'data' ] [ 'relationships' ] . has_key? ( 'actors' ) ) . to be_truthy
350350 end
351351
352- it "doesn't return optional relationship when relationship is not included" do
353- movie . actor_ids = [ ]
354- json = MovieOptionalRelationshipSerializer . new ( movie ) . serialized_json
355- serializable_hash = JSON . parse ( json )
356- expect ( serializable_hash [ 'data' ] [ 'relationships' ] . has_key? ( 'actors' ) ) . to be_falsey
352+ context "when relationship is not included" do
353+ let ( :json ) {
354+ MovieOptionalRelationshipSerializer . new ( movie , options ) . serialized_json
355+ }
356+ let ( :options ) {
357+ { }
358+ }
359+ let ( :serializable_hash ) {
360+ JSON . parse ( json )
361+ }
362+
363+ it "doesn't return optional relationship" do
364+ movie . actor_ids = [ ]
365+ expect ( serializable_hash [ 'data' ] [ 'relationships' ] . has_key? ( 'actors' ) ) . to be_falsey
366+ end
367+
368+ it "doesn't include optional relationship" do
369+ movie . actor_ids = [ ]
370+ options [ :include ] = [ :actors ]
371+ expect ( serializable_hash [ 'included' ] ) . to be_blank
372+ end
357373 end
358374 end
359375
@@ -364,10 +380,25 @@ class BlahSerializer
364380 expect ( serializable_hash [ 'data' ] [ 'relationships' ] . has_key? ( 'owner' ) ) . to be_truthy
365381 end
366382
367- it "doesn't return optional relationship when relationship is not included" do
368- json = MovieOptionalRelationshipWithParamsSerializer . new ( movie , { params : { admin : false } } ) . serialized_json
369- serializable_hash = JSON . parse ( json )
370- expect ( serializable_hash [ 'data' ] [ 'relationships' ] . has_key? ( 'owner' ) ) . to be_falsey
383+ context "when relationship is not included" do
384+ let ( :json ) {
385+ MovieOptionalRelationshipWithParamsSerializer . new ( movie , options ) . serialized_json
386+ }
387+ let ( :options ) {
388+ { params : { admin : false } }
389+ }
390+ let ( :serializable_hash ) {
391+ JSON . parse ( json )
392+ }
393+
394+ it "doesn't return optional relationship" do
395+ expect ( serializable_hash [ 'data' ] [ 'relationships' ] . has_key? ( 'owner' ) ) . to be_falsey
396+ end
397+
398+ it "doesn't include optional relationship" do
399+ options [ :include ] = [ :owner ]
400+ expect ( serializable_hash [ 'included' ] ) . to be_blank
401+ end
371402 end
372403 end
373404end
0 commit comments