Allow to get repositories by ids

This commit is contained in:
Piotr Sarnacki 2015-04-16 13:42:33 +02:00
parent a12240a0eb
commit 222a97028a
2 changed files with 12 additions and 0 deletions

View File

@ -16,6 +16,7 @@ class Travis::Api::App
# json(:repositories)
get '/' do
prefer_follower do
params['ids'] = params['ids'].split(',') if params['ids'].respond_to?(:split)
respond_with service(:find_repos, params)
end
end

View File

@ -5,6 +5,17 @@ describe 'Repos' do
let(:repo) { Repository.by_slug('svenfuchs/minimal').first }
let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.2+json' } }
describe 'with a list of ids' do
it 'returns repositories by ids' do
repos = Repository.all
ids = repos[0..1].map(&:id)
response = get "/repos?ids=#{ids.join(',')}", {}, headers
body = JSON.parse(response.body)
body['repos'].map { |r| r['id'] }.should == ids
end
end
describe 'with authenticated user' do
let(:user) { User.where(login: 'svenfuchs').first }
let(:token) { Travis::Api::App::AccessToken.create(user: user, app_id: -1) }