@@ -65,16 +65,16 @@ def create
65
65
data : [
66
66
{ type : 'books' , attributes : { title : 'The Shining' } }
67
67
]
68
- }
68
+ }
69
69
}
70
70
}
71
71
}
72
72
73
73
expect ( json_included_types )
74
74
. to match_array ( %w( states books ) )
75
- expect ( json_includes ( 'states' , :id ) )
76
- . to match_array ( [ virginia . id . to_s ] )
77
- expect ( json_includes ( 'states' , :id ) [ 0 ] ) . to eq ( virginia . id . to_s )
75
+ expect ( json_include ( 'states' ) [ 'id' ] )
76
+ . to eq ( virginia . id . to_s )
77
+ expect ( json_include ( 'states' ) [ 'id' ] ) . to eq ( virginia . id . to_s )
78
78
end
79
79
end
80
80
@@ -117,14 +117,14 @@ def update
117
117
relationships : {
118
118
books : {
119
119
data : [
120
- {
121
- type : 'books' ,
122
- attributes : {
123
- title : "The Firm" ,
120
+ {
121
+ type : 'books' ,
122
+ attributes : {
123
+ title : "The Firm" ,
124
124
genre_attributes : {
125
125
name : "Thriller"
126
- }
127
- }
126
+ }
127
+ }
128
128
}
129
129
]
130
130
}
@@ -133,7 +133,7 @@ def update
133
133
}
134
134
135
135
expect ( json_included_types ) . to match_array ( %w( books ) )
136
- expect ( json_includes ( 'books' , :id ) ) . to match_array ( [ Book . last . id . to_s ] )
136
+ expect ( json_include ( 'books' ) [ 'id' ] ) . to eq ( Book . last . id . to_s )
137
137
author . reload
138
138
expect ( author . book_ids ) . to match_array ( Book . pluck ( :id ) )
139
139
end
@@ -151,7 +151,7 @@ def update
151
151
Author . create! ( first_name : "First" , state : State . last )
152
152
Author . create! ( first_name : "Second" , state : State . last )
153
153
get :index
154
- expect ( json_ids ) . to eq ( Author . pluck ( :id ) )
154
+ expect ( json_ids ( true ) ) . to eq ( Author . pluck ( :id ) )
155
155
end
156
156
157
157
it 'should be able to override options' do
@@ -297,7 +297,7 @@ def index
297
297
298
298
it 'should limit by size, offset by number' do
299
299
get :index , params : { page : { number : 2 , size : 2 } }
300
- expect ( json_ids ) . to eq ( [ author3 . id , author4 . id ] )
300
+ expect ( json_ids ( true ) ) . to eq ( [ author3 . id , author4 . id ] )
301
301
end
302
302
303
303
context 'and a custom pagination function is given' do
@@ -394,14 +394,14 @@ def index
394
394
395
395
it 'should limit to only the requested fields' do
396
396
get :index , params : { fields : { authors : 'first_name,updated_at' } }
397
- expect ( json_items ( 0 ) . keys ) . to match_array ( %w( first-name updated-at ) )
397
+ expect ( json_items ( 0 ) . keys ) . to match_array ( %w( id jsonapi_type first-name updated-at ) )
398
398
end
399
399
400
400
it 'should still disallow fields guarded by :if' do
401
401
allow_any_instance_of ( custom_serializer )
402
402
. to receive ( :allow_hostname? ) { false }
403
403
get :index , params : { fields : { authors : 'hostname,updated_at' } }
404
- expect ( json_items ( 0 ) . keys ) . to match_array ( [ ' updated-at' ] )
404
+ expect ( json_items ( 0 ) . keys ) . to match_array ( %w( id jsonapi_type updated-at ) )
405
405
end
406
406
407
407
context 'when requesting extra fields' do
@@ -484,7 +484,7 @@ def include_foo!
484
484
485
485
it 'applies by default' do
486
486
get :index
487
- expect ( json_ids ) . to eq ( [ author3 . id ] )
487
+ expect ( json_ids ( true ) ) . to eq ( [ author3 . id ] )
488
488
end
489
489
490
490
it 'is overridable if an allowed filter' do
@@ -499,7 +499,7 @@ def include_foo!
499
499
end
500
500
501
501
get :index , params : { filter : { last_name : author4 . last_name } }
502
- expect ( json_ids ) . to eq ( [ author4 . id ] )
502
+ expect ( json_ids ( true ) ) . to eq ( [ author4 . id ] )
503
503
end
504
504
505
505
it 'is overridable if an allowed filter has a corresponding alias' do
@@ -516,36 +516,36 @@ def include_foo!
516
516
end
517
517
518
518
get :index , params : { filter : { title : author1 . first_name } }
519
- expect ( json_ids ) . to eq ( [ author1 . id ] )
519
+ expect ( json_ids ( true ) ) . to eq ( [ author1 . id ] )
520
520
end
521
521
end
522
522
523
523
context 'and the filter is allowed' do
524
524
context 'and is customized with a block' do
525
525
it 'should filter correctly via block' do
526
526
get :index , params : { filter : { first_name_prefix : 'A' } }
527
- expect ( json_ids ) . to eq ( [ author2 . id , author4 . id ] )
527
+ expect ( json_ids ( true ) ) . to eq ( [ author2 . id , author4 . id ] )
528
528
end
529
529
end
530
530
531
531
context 'with alternate param name' do
532
532
it 'should filter correctly' do
533
533
get :index , params : { filter : { title : author2 . first_name } }
534
- expect ( json_ids ) . to eq ( [ author2 . id ] )
534
+ expect ( json_ids ( true ) ) . to eq ( [ author2 . id ] )
535
535
end
536
536
end
537
537
538
538
context 'and is not customized with a block' do
539
539
it 'should provide default ActiveRecord filter' do
540
540
get :index , params : { filter : { first_name : author2 . first_name } }
541
- expect ( json_ids ) . to eq ( [ author2 . id ] )
541
+ expect ( json_ids ( true ) ) . to eq ( [ author2 . id ] )
542
542
end
543
543
end
544
544
545
545
context 'and is comma-delimited' do
546
546
it 'should automatically be parsed into a ruby array' do
547
547
get :index , params : { filter : { first_name : [ author2 . first_name , author3 . first_name ] . join ( ',' ) } }
548
- expect ( json_ids ) . to eq ( [ author2 . id , author3 . id ] )
548
+ expect ( json_ids ( true ) ) . to eq ( [ author2 . id , author3 . id ] )
549
549
end
550
550
end
551
551
0 commit comments