@@ -122,7 +122,7 @@ def index
122122 let! ( :state ) { State . create! ( name : 'Maine' ) }
123123 let! ( :bio ) { Bio . create! ( author : author1 , picture : 'imgur' , description : 'author bio' ) }
124124 let! ( :hobby1 ) { Hobby . create! ( name : 'Fishing' , authors : [ author1 ] ) }
125- let! ( :hobby2 ) { Hobby . create! ( name : 'Woodworking' , authors : [ author1 ] ) }
125+ let! ( :hobby2 ) { Hobby . create! ( name : 'Woodworking' , authors : [ author1 , author2 ] ) }
126126 let ( :house ) { House . new ( name : 'Cozy' , state : state ) }
127127 let ( :condo ) { Condo . new ( name : 'Modern' , state : state ) }
128128 let ( :genre ) { Genre . create! ( name : 'Horror' ) }
@@ -271,6 +271,19 @@ def json
271271 expect ( hobby ) . to_not have_key ( 'description' )
272272 expect ( hobby ) . to_not have_key ( 'reason' )
273273 end
274+
275+ it 'does not duplicate results' do
276+ get :index , params : { include : 'hobbies' }
277+ author1_relationships = json [ 'data' ] [ 0 ] [ 'relationships' ]
278+ author2_relationships = json [ 'data' ] [ 1 ] [ 'relationships' ]
279+
280+ author1_hobbies = author1_relationships [ 'hobbies' ] [ 'data' ]
281+ author2_hobbies = author2_relationships [ 'hobbies' ] [ 'data' ]
282+
283+ expect ( json_includes ( 'hobbies' ) . size ) . to eq ( 2 )
284+ expect ( author1_hobbies . size ) . to eq ( 2 )
285+ expect ( author2_hobbies . size ) . to eq ( 1 )
286+ end
274287 end
275288
276289 context 'sideloading self-referential' do
0 commit comments