v3: allow sorting branches by exists_on_github

This commit is contained in:
Konstantin Haase 2015-10-13 12:33:26 +02:00
parent 9461807834
commit 1a5788e2a1
2 changed files with 26 additions and 1 deletions

View File

@ -1,6 +1,9 @@
module Travis::API::V3
class Queries::Branches < Query
sortable_by :name, last_build: "builds.started_at".freeze
sortable_by :name,
last_build: "builds.started_at".freeze,
exists_on_github: "(case when branches.exists_on_github then 1 else 2 end)".freeze
default_sort "last_build:desc"
def find(repository)

View File

@ -216,6 +216,28 @@ describe Travis::API::V3::Services::Branches::Find do
}
end
describe "sorting by exists_on_github" do
before { get("/v3/repo/#{repo.id}/branches?sort_by=exists_on_github&limit=1") }
example { expect(last_response).to be_ok }
example { expect(parsed_body["@pagination"]).to be == {
"limit" => 1,
"offset" => 0,
"count" => 1,
"is_first" => true,
"is_last" => true,
"next" => nil,
"prev" => nil,
"first" => {
"@href" => "/v3/repo/#{repo.id}/branches?sort_by=exists_on_github&limit=1",
"offset" => 0,
"limit" => 1 },
"last" => {
"@href" => "/v3/repo/#{repo.id}/branches?sort_by=exists_on_github&limit=1",
"offset" => 0,
"limit" => 1 }}
}
end
describe "sorting by unknown sort field" do
before { get("/v3/repo/#{repo.id}/branches?sort_by=name:desc,foo&limit=1") }
example { expect(last_response).to be_ok }