22
33RSpec . describe 'integrated resources and adapters' , type : :controller do
44 module Integration
5+ class GenreResource < JsonapiCompliable ::Resource
6+ type :genres
7+ use_adapter JsonapiCompliable ::Adapters ::ActiveRecord
8+ end
9+
510 class BookResource < JsonapiCompliable ::Resource
611 type :books
712 use_adapter JsonapiCompliable ::Adapters ::ActiveRecord
813 allow_filter :id
14+
15+ belongs_to :genre ,
16+ scope : -> { Genre . all } ,
17+ foreign_key : :genre_id ,
18+ resource : GenreResource
919 end
1020
1121 class DwellingResource < JsonapiCompliable ::Resource
@@ -82,14 +92,15 @@ def index
8292
8393 let! ( :author1 ) { Author . create! ( first_name : 'Stephen' , dwelling : house , state : state ) }
8494 let! ( :author2 ) { Author . create! ( first_name : 'George' , dwelling : condo ) }
85- let! ( :book1 ) { Book . create! ( author : author1 , title : 'The Shining' ) }
86- let! ( :book2 ) { Book . create! ( author : author1 , title : 'The Stand' ) }
95+ let! ( :book1 ) { Book . create! ( author : author1 , genre : genre , title : 'The Shining' ) }
96+ let! ( :book2 ) { Book . create! ( author : author1 , genre : genre , title : 'The Stand' ) }
8797 let! ( :state ) { State . create! ( name : 'Maine' ) }
8898 let! ( :bio ) { Bio . create! ( author : author1 , picture : 'imgur' , description : 'author bio' ) }
8999 let! ( :hobby1 ) { Hobby . create! ( name : 'Fishing' , authors : [ author1 ] ) }
90100 let! ( :hobby2 ) { Hobby . create! ( name : 'Woodworking' , authors : [ author1 ] ) }
91101 let ( :house ) { House . new ( name : 'Cozy' ) }
92102 let ( :condo ) { Condo . new ( name : 'Modern' ) }
103+ let ( :genre ) { Genre . create! ( name : 'Horror' ) }
93104
94105 def ids_for ( type )
95106 json_includes ( type ) . map { |b | b [ 'id' ] . to_i }
@@ -115,6 +126,11 @@ def ids_for(type)
115126 expect ( json_included_types ) . to match_array ( %w( books ) )
116127 end
117128
129+ it 'allows nested sideloading' do
130+ get :index , params : { include : 'books.genre' }
131+ expect ( json_included_types ) . to match_array ( %w( books genres ) )
132+ end
133+
118134 context 'sideloading has_many' do
119135 # TODO: may want to blow up here, only for index action
120136 it 'allows pagination of sideloaded resource' do
0 commit comments