Redirect to archive logs

This commit is contained in:
Piotr Sarnacki 2013-01-28 03:04:36 +01:00
parent edc9749bce
commit 31371686c9
3 changed files with 37 additions and 6 deletions

View File

@ -45,7 +45,7 @@ GIT
GIT
remote: git://github.com/travis-ci/travis-core.git
revision: be085ccf0aa58fba8d383d6ed72d22e47dae5836
revision: 2d766c54c2fea70dfc4d937c22413eee937f002b
specs:
travis-core (0.0.1)
actionmailer (~> 3.2.11)

View File

@ -12,7 +12,20 @@ class Travis::Api::App
end
get '/:job_id/log' do
respond_with service(:find_artifact, params)
resource = service(:find_artifact, params).run
if !resource || resource.archived?
redirect archive_url("/jobs/#{params[:job_id]}/log.txt")
else
respond_with resource
end
end
def archive_url(path)
"https://#{hostname('archive')}#{path}"
end
def hostname(name)
"#{name}#{'-staging' if Travis.env == 'staging'}.#{Travis.config.host.split('.')[-2, 2].join('.')}"
end
end
end

View File

@ -18,9 +18,27 @@ describe 'Jobs' do
response.should deliver_json_for(job, version: 'v2')
end
it '/jobs/:id' do
job.log.update_attributes!(content: 'the log')
response = get "/jobs/#{job.id}/log.txt", {}, headers
response.should deliver_as_txt('the log', version: 'v2')
context 'GET /jobs/:job_id/log.txt' do
it 'returns log for a job' do
job.log.update_attributes!(content: 'the log')
response = get "/jobs/#{job.id}/log.txt", {}, headers
response.should deliver_as_txt('the log', version: 'v2')
end
context 'when log is archived' do
it 'redirects to archive' do
job.log.update_attributes!(content: 'the log', archived_at: Time.now, archive_verified: true)
response = get "/jobs/#{job.id}/log.txt", {}, headers
response.should redirect_to("https://archive.travis-ci.org/jobs/#{job.id}/log.txt")
end
end
context 'when log is missing' do
it 'redirects to archive' do
job.log.destroy
response = get "/jobs/#{job.id}/log.txt", {}, headers
response.should redirect_to("https://archive.travis-ci.org/jobs/#{job.id}/log.txt")
end
end
end
end