File tree Expand file tree Collapse file tree 2 files changed +51
-1
lines changed Expand file tree Collapse file tree 2 files changed +51
-1
lines changed Original file line number Diff line number Diff line change @@ -209,7 +209,8 @@ def parse_filter(hash)
209
209
key = key . to_sym
210
210
211
211
if association? ( key )
212
- hash [ key ] [ :filter ] . merge! ( value )
212
+ k , v = Hash ( value ) . to_a . first
213
+ hash [ key ] [ :filter ] [ k . to_sym ] = v
213
214
else
214
215
hash [ resource . type ] [ :filter ] [ key ] = value
215
216
end
Original file line number Diff line number Diff line change @@ -278,4 +278,53 @@ def json
278
278
expect ( author [ :books ] [ 0 ] . instance_variable_get ( :@the_genre ) ) . to eq ( genre )
279
279
end
280
280
end
281
+
282
+
283
+ context 'when sideload has required filter' do
284
+ before do
285
+ a = author
286
+ book_resource . class_eval do
287
+ allow_filter :required , required : true do |scope , value |
288
+ scope . where ( author_id : a . id )
289
+ end
290
+ end
291
+ end
292
+
293
+ context 'and no required filters are provided' do
294
+ before do
295
+ params [ :include ] = 'books'
296
+ end
297
+
298
+ it 'raises an error' do
299
+ expect {
300
+ scope . resolve
301
+ } . to raise_error ( JsonapiCompliable ::Errors ::RequiredFilter , 'The required filter "required" was not provided' )
302
+ end
303
+
304
+ end
305
+
306
+ context 'and sideloaded filter is provided with symbolized keys' do
307
+ before do
308
+ params [ :include ] = 'books'
309
+ params [ :filter ] = { books : { required : true } }
310
+ end
311
+
312
+ it 'should return results' do
313
+ author = scope . resolve . first
314
+ expect ( author [ :books ] ) . to eq ( [ book1 , book2 ] )
315
+ end
316
+ end
317
+
318
+ context 'and sideloaded filter is provided with stringified keys' do
319
+ before do
320
+ params [ :include ] = 'books'
321
+ params [ :filter ] = { 'books' => { 'required' => true } }
322
+ end
323
+
324
+ it 'should return results' do
325
+ author = scope . resolve . first
326
+ expect ( author [ :books ] ) . to eq ( [ book1 , book2 ] )
327
+ end
328
+ end
329
+ end
281
330
end
You can’t perform that action at this time.
0 commit comments