diff --git a/app/controllers/api/v1/subjects_controller.rb b/app/controllers/api/v1/subjects_controller.rb index e14a4fe0f..db8a70789 100644 --- a/app/controllers/api/v1/subjects_controller.rb +++ b/app/controllers/api/v1/subjects_controller.rb @@ -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 diff --git a/app/serializers/subject_serializer.rb b/app/serializers/subject_serializer.rb index 7615397ae..da96fe5df 100644 --- a/app/serializers/subject_serializer.rb +++ b/app/serializers/subject_serializer.rb @@ -9,6 +9,8 @@ class SubjectSerializer preload :locations, :project, :collections, :subject_sets + can_sort_by :id + def locations @model.ordered_locations.map do |loc| { diff --git a/spec/controllers/api/v1/subjects_controller_spec.rb b/spec/controllers/api/v1/subjects_controller_spec.rb index 703d58c39..cf5abfcc5 100644 --- a/spec/controllers/api/v1/subjects_controller_spec.rb +++ b/spec/controllers/api/v1/subjects_controller_spec.rb @@ -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 @@ -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