Commit 7c3ca863 authored by Valery Sizov's avatar Valery Sizov

Add order option for projects API

parent 5619c7b9
......@@ -22,8 +22,13 @@ module API
projects = projects.search(params[:search])
end
if params[:ci_enabled_first].present?
projects.includes(:gitlab_ci_service).
reorder("services.active DESC, projects.#{project_order_by} #{project_sort}")
else
projects.reorder(project_order_by => project_sort)
end
end
def project_order_by
order_fields = %w(id name path created_at updated_at last_activity_at)
......
......@@ -86,6 +86,15 @@ describe API::API, api: true do
expect(json_response).to be_an Array
expect(json_response.first['id']).to eq(project3.id)
end
it 'returns projects in the correct order when ci_enabled_first parameter is passed' do
[project, project2, project3].each{ |project| project.build_missing_services }
project2.gitlab_ci_service.update(active: true, token: "token", project_url: "url")
get api('/projects', user), { ci_enabled_first: 'true'}
expect(response.status).to eq(200)
expect(json_response).to be_an Array
expect(json_response.first['id']).to eq(project2.id)
end
end
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment