Redirect /:owner/:name/builds.json to a proper api endpoint

This commit is contained in:
Piotr Sarnacki 2012-11-08 15:59:12 +01:00
parent d94b001e81
commit de38b3d297
2 changed files with 12 additions and 2 deletions

View File

@ -24,6 +24,10 @@ class Travis::Web::ApiRedirect < Sinatra::Base
redirect!
end
get '/:owner_name/:name/builds.json' do
redirect! "/repos#{request.fullpath}"
end
after do
redirect! if catch_all? and api_call?
end
@ -40,8 +44,8 @@ class Travis::Web::ApiRedirect < Sinatra::Base
settings.api_types.include? preferred
end
def redirect!
path = File.join(settings.api_endpoint, request.fullpath)
def redirect!(path = nil)
path = File.join(settings.api_endpoint, path || request.fullpath)
redirect(path, 301)
end
end

View File

@ -30,4 +30,10 @@ describe Travis::Web::ApiRedirect do
it 'does not redirect asset requests' do
get('/version').should_not be_redirect
end
it 'redirects /:owner_name/:name/builds.json' do
response = get('/foo/bar/builds.json')
response.should be_redirect
response.headers['Location'].should == 'https://api.travis-ci.org/repos/foo/bar/builds.json'
end
end