2016-06-02 11:05:42 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe MergeRequests::AddTodoWhenBuildFailsService do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
let(:merge_request) { create(:merge_request) }
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:project) { create(:project, :repository) }
|
2016-06-02 11:05:42 +05:30
|
|
|
let(:sha) { '1234567890abcdef1234567890abcdef12345678' }
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:ref) { merge_request.source_branch }
|
|
|
|
|
|
|
|
let(:pipeline) do
|
|
|
|
create(:ci_pipeline_with_one_job, ref: ref,
|
|
|
|
project: project,
|
|
|
|
sha: sha)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:service) do
|
|
|
|
described_class.new(project, user, commit_message: 'Awesome message')
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:todo_service) { spy('todo service') }
|
2016-06-02 11:05:42 +05:30
|
|
|
|
|
|
|
let(:merge_request) do
|
2017-08-17 22:00:37 +05:30
|
|
|
create(:merge_request, merge_user: user,
|
|
|
|
source_branch: 'master',
|
|
|
|
target_branch: 'feature',
|
|
|
|
source_project: project,
|
|
|
|
target_project: project,
|
2016-06-02 11:05:42 +05:30
|
|
|
state: 'opened')
|
|
|
|
end
|
|
|
|
|
|
|
|
before do
|
2017-08-17 22:00:37 +05:30
|
|
|
allow_any_instance_of(MergeRequest)
|
|
|
|
.to receive(:head_pipeline)
|
|
|
|
.and_return(pipeline)
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
allow(service).to receive(:todo_service).and_return(todo_service)
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#execute' do
|
|
|
|
context 'commit status with ref' do
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:commit_status) do
|
|
|
|
create(:generic_commit_status, ref: ref, pipeline: pipeline)
|
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
|
|
|
|
it 'notifies the todo service' do
|
|
|
|
expect(todo_service).to receive(:merge_request_build_failed).with(merge_request)
|
|
|
|
service.execute(commit_status)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'commit status with non-HEAD ref' do
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:commit_status) { create(:generic_commit_status, ref: ref) }
|
2016-06-02 11:05:42 +05:30
|
|
|
|
|
|
|
it 'does not notify the todo service' do
|
|
|
|
expect(todo_service).not_to receive(:merge_request_build_failed)
|
|
|
|
service.execute(commit_status)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'commit status without ref' do
|
|
|
|
let(:commit_status) { create(:generic_commit_status) }
|
|
|
|
|
|
|
|
it 'does not notify the todo service' do
|
|
|
|
expect(todo_service).not_to receive(:merge_request_build_failed)
|
|
|
|
service.execute(commit_status)
|
|
|
|
end
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
context 'when commit status is a build allowed to fail' do
|
|
|
|
let(:commit_status) do
|
|
|
|
create(:ci_build, :allowed_to_fail, ref: ref, pipeline: pipeline)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'does not create todo' do
|
|
|
|
expect(todo_service).not_to receive(:merge_request_build_failed)
|
|
|
|
|
|
|
|
service.execute(commit_status)
|
|
|
|
end
|
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
describe '#close' do
|
|
|
|
context 'commit status with ref' do
|
2016-06-16 23:09:34 +05:30
|
|
|
let(:commit_status) { create(:generic_commit_status, ref: merge_request.source_branch, pipeline: pipeline) }
|
2016-06-02 11:05:42 +05:30
|
|
|
|
|
|
|
it 'notifies the todo service' do
|
|
|
|
expect(todo_service).to receive(:merge_request_build_retried).with(merge_request)
|
|
|
|
service.close(commit_status)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'commit status with non-HEAD ref' do
|
|
|
|
let(:commit_status) { create(:generic_commit_status, ref: merge_request.source_branch) }
|
|
|
|
|
|
|
|
it 'does not notify the todo service' do
|
|
|
|
expect(todo_service).not_to receive(:merge_request_build_retried)
|
|
|
|
service.close(commit_status)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'commit status without ref' do
|
|
|
|
let(:commit_status) { create(:generic_commit_status) }
|
|
|
|
|
|
|
|
it 'does not notify the todo service' do
|
|
|
|
expect(todo_service).not_to receive(:merge_request_build_retried)
|
|
|
|
service.close(commit_status)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
describe '#close_all' do
|
|
|
|
context 'when using pipeline that belongs to merge request' do
|
|
|
|
it 'resolves todos about failed builds for pipeline' do
|
|
|
|
service.close_all(pipeline)
|
|
|
|
|
|
|
|
expect(todo_service)
|
|
|
|
.to have_received(:merge_request_build_retried)
|
|
|
|
.with(merge_request)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when pipeline is not related to merge request' do
|
|
|
|
let(:pipeline) { create(:ci_empty_pipeline) }
|
|
|
|
|
|
|
|
it 'does not resolve any todos about failed builds' do
|
|
|
|
service.close_all(pipeline)
|
|
|
|
|
|
|
|
expect(todo_service)
|
|
|
|
.not_to have_received(:merge_request_build_retried)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
end
|