
: add require sidekiq to the sidekiq.rb update Gemfile.lock bump travis-sidekiqs correct require statement fix another request connect to the database add current user add current user correctly add current user correctly add puts to see were in the condition we are missing invertted comma add comments to the worker I HAVE NO IDEA Revert "I HAVE NO IDEA" This reverts commit 8bd1259bf4ea1b479f9391847a4700b7b15efe57. change the id and source to symbols in the params because siedekiq expects that add more printout setup database connection, metrics and notification correct the test
96 lines
3.3 KiB
Ruby
96 lines
3.3 KiB
Ruby
require 'spec_helper'
|
|
|
|
describe 'Builds' do
|
|
let(:repo) { Repository.by_slug('svenfuchs/minimal').first }
|
|
let(:build) { repo.builds.first }
|
|
let(:headers) { { 'HTTP_ACCEPT' => 'application/vnd.travis-ci.2+json' } }
|
|
|
|
it 'GET /builds?repository_id=1' do
|
|
response = get '/builds', { repository_id: repo.id }, headers
|
|
response.should deliver_json_for(repo.builds.order('id DESC'), version: 'v2')
|
|
end
|
|
|
|
it 'GET /builds/1' do
|
|
response = get "/builds/#{build.id}", {}, headers
|
|
response.should deliver_json_for(build, version: 'v2')
|
|
end
|
|
|
|
it 'GET /builds/1?repository_id=1' do
|
|
response = get "/builds/#{build.id}", { repository_id: repo.id }, headers
|
|
response.should deliver_json_for(build, version: 'v2')
|
|
end
|
|
|
|
it 'GET /repos/svenfuchs/minimal/builds' do
|
|
response = get '/repos/svenfuchs/minimal/builds', {}, headers
|
|
response.should deliver_json_for(repo.builds.order('id DESC'), version: 'v2', type: :builds)
|
|
end
|
|
|
|
it 'GET /repos/svenfuchs/minimal/builds?ids=1,2' do
|
|
ids = repo.builds.map(&:id).sort.join(',')
|
|
response = get "/repos/svenfuchs/minimal/builds?ids=#{ids}", {}, headers
|
|
response.should deliver_json_for(repo.builds.order('id ASC'), version: 'v2')
|
|
end
|
|
|
|
it 'GET /builds?ids=1,2' do
|
|
ids = repo.builds.map(&:id).sort.join(',')
|
|
response = get "/builds?ids=#{ids}", {}, headers
|
|
response.should deliver_json_for(repo.builds.order('id ASC'), version: 'v2')
|
|
end
|
|
|
|
it 'GET /repos/svenfuchs/minimal/builds/1' do
|
|
response = get "/repos/svenfuchs/minimal/builds/#{build.id}", {}, headers
|
|
response.should deliver_json_for(build, version: 'v2')
|
|
end
|
|
|
|
it 'GET /builds/1?repository_id=1&branches=true' do
|
|
response = get "/builds?repository_id=#{repo.id}&branches=true", {}, headers
|
|
response.should deliver_json_for(repo.last_finished_builds_by_branches, version: 'v2')
|
|
end
|
|
|
|
describe 'POST /builds/:id/cancel' do
|
|
let(:user) { User.where(login: 'svenfuchs').first }
|
|
let(:token) { Travis::Api::App::AccessToken.create(user: user, app_id: -1) }
|
|
|
|
before {
|
|
headers.merge! 'HTTP_AUTHORIZATION' => "token #{token}"
|
|
user.permissions.create!(repository_id: build.repository.id, :pull => true, :push => true)
|
|
}
|
|
|
|
context 'when user does not have rights to cancel the build' do
|
|
before { user.permissions.destroy_all }
|
|
|
|
it 'responds with 403' do
|
|
response = post "/builds/#{build.id}/cancel", {}, headers
|
|
response.status.should == 403
|
|
end
|
|
end
|
|
|
|
context 'when build is not cancelable' do
|
|
before { build.matrix.each { |j| j.update_attribute(:state, 'passed') } }
|
|
|
|
it 'responds with 422' do
|
|
response = post "/builds/#{build.id}/cancel", {}, headers
|
|
response.status.should == 422
|
|
end
|
|
end
|
|
|
|
context 'when build can be canceled' do
|
|
before do
|
|
Travis::Sidekiq::BuildCancellation.stubs(:perform_async)
|
|
build.matrix.each { |j| j.update_attribute(:state, 'created') }
|
|
build.update_attribute(:state, 'created')
|
|
end
|
|
|
|
it 'cancels the build' do
|
|
Travis::Sidekiq::BuildCancellation.expects(:perform_async).with( id: build.id.to_s, user_id: user.id, source: 'api')
|
|
post "/builds/#{build.id}/cancel", {}, headers
|
|
end
|
|
|
|
it 'responds with 204' do
|
|
response = post "/builds/#{build.id}/cancel", {}, headers
|
|
response.status.should == 204
|
|
end
|
|
end
|
|
end
|
|
end
|