2
2
3
3
RSpec . describe 'integrated resources and adapters' , type : :controller do
4
4
module Integration
5
+ class GenreResource < JsonapiCompliable ::Resource
6
+ type :genres
7
+ use_adapter JsonapiCompliable ::Adapters ::ActiveRecord
8
+ end
9
+
5
10
class BookResource < JsonapiCompliable ::Resource
6
11
type :books
7
12
use_adapter JsonapiCompliable ::Adapters ::ActiveRecord
8
13
allow_filter :id
14
+
15
+ belongs_to :genre ,
16
+ scope : -> { Genre . all } ,
17
+ foreign_key : :genre_id ,
18
+ resource : GenreResource
9
19
end
10
20
11
21
class DwellingResource < JsonapiCompliable ::Resource
@@ -82,14 +92,15 @@ def index
82
92
83
93
let! ( :author1 ) { Author . create! ( first_name : 'Stephen' , dwelling : house , state : state ) }
84
94
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' ) }
87
97
let! ( :state ) { State . create! ( name : 'Maine' ) }
88
98
let! ( :bio ) { Bio . create! ( author : author1 , picture : 'imgur' , description : 'author bio' ) }
89
99
let! ( :hobby1 ) { Hobby . create! ( name : 'Fishing' , authors : [ author1 ] ) }
90
100
let! ( :hobby2 ) { Hobby . create! ( name : 'Woodworking' , authors : [ author1 ] ) }
91
101
let ( :house ) { House . new ( name : 'Cozy' ) }
92
102
let ( :condo ) { Condo . new ( name : 'Modern' ) }
103
+ let ( :genre ) { Genre . create! ( name : 'Horror' ) }
93
104
94
105
def ids_for ( type )
95
106
json_includes ( type ) . map { |b | b [ 'id' ] . to_i }
@@ -115,6 +126,11 @@ def ids_for(type)
115
126
expect ( json_included_types ) . to match_array ( %w( books ) )
116
127
end
117
128
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
+
118
134
context 'sideloading has_many' do
119
135
# TODO: may want to blow up here, only for index action
120
136
it 'allows pagination of sideloaded resource' do
0 commit comments