v3: allow filtering branches by exists_on_github

This commit is contained in:
Konstantin Haase 2015-10-13 12:42:03 +02:00
parent 1a5788e2a1
commit 1d783129ce
3 changed files with 23 additions and 1 deletions

View File

@ -1,5 +1,7 @@
module Travis::API::V3
class Queries::Branches < Query
params :exists_on_github, prefix: :branch
sortable_by :name,
last_build: "builds.started_at".freeze,
exists_on_github: "(case when branches.exists_on_github then 1 else 2 end)".freeze
@ -7,7 +9,12 @@ module Travis::API::V3
default_sort "last_build:desc"
def find(repository)
sort repository.branches
sort filter(repository.branches)
end
def filter(list)
list = list.where(exists_on_github: bool(exists_on_github)) unless exists_on_github.nil?
list
end
end
end

View File

@ -1,5 +1,6 @@
module Travis::API::V3
class Services::Branches::Find < Service
params :exists_on_github, prefix: :branch
paginate
def run!

View File

@ -172,6 +172,20 @@ describe Travis::API::V3::Services::Branches::Find do
}
end
describe "filtering by exists_on_github" do
describe "false" do
before { get("/v3/repo/#{repo.id}/branches?branch.exists_on_github=false") }
example { expect(last_response).to be_ok }
example { expect(parsed_body["branches"]).to be_empty }
end
describe "true" do
before { get("/v3/repo/#{repo.id}/branches?branch.exists_on_github=true") }
example { expect(last_response).to be_ok }
example { expect(parsed_body["branches"]).not_to be_empty }
end
end
describe "sorting by name" do
before { get("/v3/repo/#{repo.id}/branches?sort_by=name&limit=1") }
example { expect(last_response).to be_ok }