Add /requests/:id endpoint

This commit is contained in:
Piotr Sarnacki 2014-03-12 10:50:16 +01:00
parent 23dd318412
commit 400b6ae6ee
2 changed files with 24 additions and 8 deletions

View File

@ -17,6 +17,10 @@ class Travis::Api::App
{ "error" => "Repository could not be found" } { "error" => "Repository could not be found" }
end end
end end
get '/:id' do
respond_with service(:find_request, params)
end
end end
end end
end end

View File

@ -3,16 +3,28 @@ require 'spec_helper'
describe 'Requests' do describe 'Requests' do
let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.2+json' } } let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.2+json' } }
it 'fetches requests' do describe '/requests' do
repo = Factory.create(:repository) it 'fetches requests' do
request = Factory.create(:request, repository: repo) repo = Factory.create(:repository)
request = Factory.create(:request, repository: repo)
response = get '/requests', { repository_id: repo.id }, headers response = get '/requests', { repository_id: repo.id }, headers
response.should deliver_json_for(repo.requests, version: 'v2', type: 'requests') response.should deliver_json_for(repo.requests, version: 'v2', type: 'requests')
end
it 'returns an error response if repo can\'t be found' do
response = get '/requests', { repository_id: 0 }, headers
JSON.parse(response.body)['error'].should == "Repository could not be found"
end
end end
it 'returns an error response if repo can\'t be found' do describe '/requests/:id' do
response = get '/requests', { repository_id: 0 }, headers it 'fetches a request' do
JSON.parse(response.body)['error'].should == "Repository could not be found" repo = Factory.create(:repository)
request = Factory.create(:request, repository: repo)
response = get "/requests/#{request.id}", {}, headers
response.should deliver_json_for(request, version: 'v2', type: 'request')
end
end end
end end