Skip to content

Commit 3c45987

Browse files
author
Lee Richmond
committed
Fix sort
1 parent eb590ae commit 3c45987

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

lib/jsonapi_compliable/base.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ def jsonapi_includes(scope)
160160
end
161161

162162
def jsonapi_sort(scope)
163-
sort_param = params[:sort] || '-id'
164-
dir = sort_param.starts_with?('-') ? :asc : :desc
163+
sort_param = params[:sort] || 'id'
164+
dir = sort_param.starts_with?('-') ? :desc : :asc
165165
att = sort_param.sub('-', '').to_sym
166166

167167
scope = if custom_sort = _jsonapi_config._sort

spec/jsonapi_compliable_spec.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,19 +249,19 @@ def index
249249
end
250250

251251
context 'asc' do
252-
let(:sort_param) { '-first_name' }
252+
let(:sort_param) { 'first_name' }
253253

254254
it { is_expected.to eq(%w(Philip Stephen)) }
255255
end
256256

257257
context 'desc' do
258-
let(:sort_param) { 'first_name' }
258+
let(:sort_param) { '-first_name' }
259259

260260
it { is_expected.to eq(%w(Stephen Philip)) }
261261
end
262262

263263
context 'when given a custom sort function' do
264-
let(:sort_param) { '-first_name' }
264+
let(:sort_param) { 'first_name' }
265265

266266
before do
267267
controller.class_eval do

0 commit comments

Comments
 (0)