Skip to content

Commit

Permalink
add sort functionality to subjects and sort by id default (#4359)
Browse files Browse the repository at this point in the history
* add sort functionality to subjects and sort by id default

* add controller test for id default

* hound cleanups

* hound cleanups
  • Loading branch information
Tooyosi authored Jul 17, 2024
1 parent a2c663c commit fc632d2
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/controllers/api/v1/subjects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class Api::V1::SubjectsController < Api::ApiController
before_action :check_subject_limit, only: :create

def index
params[:sort] = 'id' if params[:sort].blank?

case params[:sort]
when 'queued'
queued
Expand Down
2 changes: 2 additions & 0 deletions app/serializers/subject_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ class SubjectSerializer

preload :locations, :project, :collections, :subject_sets

can_sort_by :id

def locations
@model.ordered_locations.map do |loc|
{
Expand Down
8 changes: 8 additions & 0 deletions spec/controllers/api/v1/subjects_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
get :index
end

it 'defaults sort parameter to id' do
expect(controller.params[:sort]).to eq('id')
end

it_behaves_like "an api response"

it "should return 200" do
Expand Down Expand Up @@ -85,6 +89,10 @@
get :index, params: request_params
end

it 'does not default sort parameter to id' do
expect(controller.params[:sort]).not_to eq('id')
end

it "should return 200" do
expect(response.status).to eq(200)
end
Expand Down

0 comments on commit fc632d2

Please sign in to comment.