Skip to content

Commit

Permalink
force ascending order if specified
Browse files Browse the repository at this point in the history
  • Loading branch information
Jillian Tullo committed Jul 13, 2017
1 parent 8eb967f commit 291631d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions app/controllers/api/base_controller/parameters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ def sort_directive(klass, attr, order, options)
if order
arel = arel.lower if options.map(&:downcase).include?("ignore_case")
arel = arel.desc if order.downcase == "desc"
arel = arel.asc if order.downcase == "asc"
else
arel = arel.asc
end
arel
end
Expand Down
14 changes: 14 additions & 0 deletions spec/requests/api/querying_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,20 @@ def create_vms_by_name(names)
expect(response).to have_http_status(:bad_request)
expect(response.parsed_body).to include(expected)
end

it 'allows sorting by asc when other filters are applied' do
api_basic_authorize collection_action_identifier(:services, :read, :get)
svc1, _svc2 = FactoryGirl.create_list(:service, 2)
dept = FactoryGirl.create(:classification_department)
FactoryGirl.create(:classification_tag, :name => 'finance', :parent => dept)
Classification.classify(svc1, 'department', 'finance')

run_get services_url, :sort_by => 'created_at', :filter => ['tags.name=/managed/department/finance'],
:sort_order => 'asc', :limit => 20, :offset => 0

expect(response).to have_http_status(:ok)
expect(response.parsed_body['subcount']).to eq(1)
end
end

describe "Filtering vms" do
Expand Down

0 comments on commit 291631d

Please sign in to comment.