File tree Expand file tree Collapse file tree 3 files changed +10
-3
lines changed Expand file tree Collapse file tree 3 files changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,10 @@ def default_page_size
21
21
20
22
22
end
23
23
24
+ def default_sort
25
+ 'id'
26
+ end
27
+
24
28
def jsonapi_scope ( scope ,
25
29
filter : true ,
26
30
includes : true ,
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ def apply_custom_scope
15
15
private
16
16
17
17
def sort_param
18
- @sort_param ||= ( params [ :sort ] || 'id' )
18
+ @sort_param ||= ( params [ :sort ] || @controller . default_sort )
19
19
end
20
20
21
21
def direction
Original file line number Diff line number Diff line change @@ -14,10 +14,13 @@ def index
14
14
Author . create! ( first_name : 'Philip' )
15
15
end
16
16
17
- it 'defaults sort to id asc' do
17
+ it 'defaults sort to controller default_sort' do
18
+ expect ( controller ) . to receive ( :default_sort ) { 'id' }
18
19
get :index
19
- expect ( json_ids . length ) . to eq ( 2 )
20
20
expect ( json_ids ( true ) ) . to eq ( Author . pluck ( :id ) )
21
+ expect ( controller ) . to receive ( :default_sort ) { '-id' }
22
+ get :index
23
+ expect ( json_ids ( true ) ) . to eq ( Author . pluck ( :id ) . reverse )
21
24
end
22
25
23
26
context 'when passing sort param' do
You can’t perform that action at this time.
0 commit comments