Add specs for RemoveLog service
Status code is debatable; I opted for 422 when the job is still running, and for 500 if unexpected error happened
This commit is contained in:
parent
cad6c4e68e
commit
5c079f8e66
|
@ -8,6 +8,24 @@ class Travis::Api::App
|
|||
get '/:id' do |id|
|
||||
respond_with service(:find_log, params)
|
||||
end
|
||||
|
||||
# Clears up the content of the log by the *job id*
|
||||
# Optionally takes parameter *reason*
|
||||
patch '/:id' do |id|
|
||||
begin
|
||||
result = self.service(:remove_log, params)
|
||||
respond_with result
|
||||
rescue Travis::AuthorizationDenied => ade
|
||||
status 401
|
||||
{ error: { message: ade.message } }
|
||||
rescue Travis::JobUnfinished => jue
|
||||
status 422
|
||||
{ error: { message: "Job #{id} is not finished" } }
|
||||
rescue => e
|
||||
status 500
|
||||
{ error: { message: "Unexpected error occurred: #{e.message}" } }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
38
spec/unit/endpoint/logs_spec.rb
Normal file
38
spec/unit/endpoint/logs_spec.rb
Normal file
|
@ -0,0 +1,38 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Travis::Api::App::Endpoint::Logs do
|
||||
let(:user) { Factory(:user) }
|
||||
let(:job) { Factory(:test, owner: user, log: Factory(:log)) }
|
||||
let(:provider) { Factory(:annotation_provider) }
|
||||
|
||||
describe "GET /logs/:id/" do
|
||||
it "finds log successfully" do
|
||||
get("/logs/#{job.log.id}", {}, "HTTP_ACCEPT" => "application/vnd.travis-ci.2+json, */*; q=0.01").should be_ok
|
||||
end
|
||||
end
|
||||
|
||||
describe "PATCH /logs/:id/" do
|
||||
before do
|
||||
Travis::Services::RemoveLog.any_instance.stubs(:current_user).returns user
|
||||
end
|
||||
|
||||
context "user is unauthorized" do
|
||||
it 'returns status 401' do
|
||||
response = patch("/logs/#{job.id}")
|
||||
response.status.should == 401
|
||||
JSON.parse(response.body)['error']['message'].should =~ Regexp.new("insufficient permission")
|
||||
end
|
||||
end
|
||||
|
||||
context 'job is still running' do
|
||||
it 'returns status 422' do
|
||||
job.stubs(:finished?).returns false
|
||||
user.stubs(:permission?).with(:push, anything).returns true
|
||||
|
||||
response = patch("/logs/#{job.id}")
|
||||
response.status.should == 422
|
||||
JSON.parse(response.body)['error']['message'].should =~ Regexp.new("Job .*is (not |un)finished")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -213,6 +213,7 @@ Gem::Specification.new do |s|
|
|||
"spec/unit/endpoint/endpoints_spec.rb",
|
||||
"spec/unit/endpoint/hooks_spec.rb",
|
||||
"spec/unit/endpoint/jobs_spec.rb",
|
||||
"spec/unit/endpoint/logs_spec.rb",
|
||||
"spec/unit/endpoint/repos_spec.rb",
|
||||
"spec/unit/endpoint/users_spec.rb",
|
||||
"spec/unit/endpoint_spec.rb",
|
||||
|
|
Loading…
Reference in New Issue
Block a user