2016-04-27 18:34:42 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2017-05-09 04:15:34 +00:00
|
|
|
feature 'Only allow merge requests to be merged if the pipeline succeeds', feature: true, js: true do
|
2016-11-18 17:30:07 +00:00
|
|
|
let(:merge_request) { create(:merge_request_with_diffs) }
|
|
|
|
let(:project) { merge_request.target_project }
|
2016-04-27 18:34:42 +00:00
|
|
|
|
|
|
|
before do
|
2017-06-21 23:44:10 +00:00
|
|
|
sign_in merge_request.author
|
2016-04-27 18:34:42 +00:00
|
|
|
|
2016-06-07 11:01:34 +00:00
|
|
|
project.team << [merge_request.author, :master]
|
2016-04-27 18:34:42 +00:00
|
|
|
end
|
|
|
|
|
2017-05-09 04:15:34 +00:00
|
|
|
context 'project does not have CI enabled', js: true do
|
2016-06-07 11:01:34 +00:00
|
|
|
it 'allows MR to be merged' do
|
2016-04-27 18:34:42 +00:00
|
|
|
visit_merge_request(merge_request)
|
2016-06-07 11:01:34 +00:00
|
|
|
|
2017-05-17 18:25:13 +00:00
|
|
|
wait_for_requests
|
2017-05-09 04:15:34 +00:00
|
|
|
|
|
|
|
expect(page).to have_button 'Merge'
|
2016-04-27 18:34:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-05-09 04:15:34 +00:00
|
|
|
context 'when project has CI enabled', js: true do
|
2016-11-18 17:30:07 +00:00
|
|
|
given!(:pipeline) do
|
|
|
|
create(:ci_empty_pipeline,
|
|
|
|
project: project,
|
|
|
|
sha: merge_request.diff_head_sha,
|
|
|
|
ref: merge_request.source_branch,
|
2017-05-19 20:51:07 +00:00
|
|
|
status: status, head_pipeline_of: merge_request)
|
2016-11-18 17:30:07 +00:00
|
|
|
end
|
2016-04-27 18:34:42 +00:00
|
|
|
|
2017-02-17 13:56:13 +00:00
|
|
|
context 'when merge requests can only be merged if the pipeline succeeds' do
|
2016-04-27 18:34:42 +00:00
|
|
|
before do
|
2017-02-17 13:56:13 +00:00
|
|
|
project.update_attribute(:only_allow_merge_if_pipeline_succeeds, true)
|
2016-04-27 18:34:42 +00:00
|
|
|
end
|
|
|
|
|
2016-06-07 11:01:34 +00:00
|
|
|
context 'when CI is running' do
|
2016-11-18 17:30:07 +00:00
|
|
|
given(:status) { :running }
|
2016-06-07 11:01:34 +00:00
|
|
|
|
|
|
|
it 'does not allow to merge immediately' do
|
2016-04-27 18:34:42 +00:00
|
|
|
visit_merge_request(merge_request)
|
|
|
|
|
2017-05-17 18:25:13 +00:00
|
|
|
wait_for_requests
|
2017-05-09 04:15:34 +00:00
|
|
|
|
2017-04-06 13:55:11 +00:00
|
|
|
expect(page).to have_button 'Merge when pipeline succeeds'
|
|
|
|
expect(page).not_to have_button 'Select merge moment'
|
2016-04-27 18:34:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-07 11:01:34 +00:00
|
|
|
context 'when CI failed' do
|
2016-11-18 17:30:07 +00:00
|
|
|
given(:status) { :failed }
|
|
|
|
|
|
|
|
it 'does not allow MR to be merged' do
|
|
|
|
visit_merge_request(merge_request)
|
|
|
|
|
2017-05-17 18:25:13 +00:00
|
|
|
wait_for_requests
|
2017-05-09 04:15:34 +00:00
|
|
|
|
|
|
|
expect(page).to have_css('button[disabled="disabled"]', text: 'Merge')
|
2017-01-26 11:52:58 +00:00
|
|
|
expect(page).to have_content('Please retry the job or push a new commit to fix the failure.')
|
2016-11-18 17:30:07 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when CI canceled' do
|
|
|
|
given(:status) { :canceled }
|
2016-06-07 11:01:34 +00:00
|
|
|
|
|
|
|
it 'does not allow MR to be merged' do
|
2016-04-27 18:34:42 +00:00
|
|
|
visit_merge_request(merge_request)
|
|
|
|
|
2017-05-17 18:25:13 +00:00
|
|
|
wait_for_requests
|
2017-05-09 04:15:34 +00:00
|
|
|
|
|
|
|
expect(page).not_to have_button 'Merge'
|
2017-01-26 11:52:58 +00:00
|
|
|
expect(page).to have_content('Please retry the job or push a new commit to fix the failure.')
|
2016-04-27 18:34:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-07 11:01:34 +00:00
|
|
|
context 'when CI succeeded' do
|
2016-11-18 17:30:07 +00:00
|
|
|
given(:status) { :success }
|
|
|
|
|
|
|
|
it 'allows MR to be merged' do
|
|
|
|
visit_merge_request(merge_request)
|
|
|
|
|
2017-05-17 18:25:13 +00:00
|
|
|
wait_for_requests
|
2017-05-09 04:15:34 +00:00
|
|
|
|
|
|
|
expect(page).to have_button 'Merge'
|
2016-11-18 17:30:07 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when CI skipped' do
|
|
|
|
given(:status) { :skipped }
|
2016-06-07 11:01:34 +00:00
|
|
|
|
|
|
|
it 'allows MR to be merged' do
|
2016-04-27 18:34:42 +00:00
|
|
|
visit_merge_request(merge_request)
|
|
|
|
|
2017-05-17 18:25:13 +00:00
|
|
|
wait_for_requests
|
2017-05-09 04:15:34 +00:00
|
|
|
|
|
|
|
expect(page).to have_button 'Merge'
|
2016-04-27 18:34:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-07 11:01:34 +00:00
|
|
|
context 'when merge requests can be merged when the build failed' do
|
2016-04-27 18:34:42 +00:00
|
|
|
before do
|
2017-02-17 13:56:13 +00:00
|
|
|
project.update_attribute(:only_allow_merge_if_pipeline_succeeds, false)
|
2016-04-27 18:34:42 +00:00
|
|
|
end
|
|
|
|
|
2016-06-07 11:01:34 +00:00
|
|
|
context 'when CI is running' do
|
2016-11-18 17:30:07 +00:00
|
|
|
given(:status) { :running }
|
2016-06-07 11:01:34 +00:00
|
|
|
|
2017-05-09 04:15:34 +00:00
|
|
|
it 'allows MR to be merged immediately' do
|
2016-04-27 18:34:42 +00:00
|
|
|
visit_merge_request(merge_request)
|
|
|
|
|
2017-05-17 18:25:13 +00:00
|
|
|
wait_for_requests
|
2017-05-09 04:15:34 +00:00
|
|
|
|
2017-04-06 13:55:11 +00:00
|
|
|
expect(page).to have_button 'Merge when pipeline succeeds'
|
2016-04-27 18:34:42 +00:00
|
|
|
|
2017-04-06 13:55:11 +00:00
|
|
|
click_button 'Select merge moment'
|
|
|
|
expect(page).to have_content 'Merge immediately'
|
2016-04-27 18:34:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-07 11:01:34 +00:00
|
|
|
context 'when CI failed' do
|
2016-11-18 17:30:07 +00:00
|
|
|
given(:status) { :failed }
|
2016-06-07 11:01:34 +00:00
|
|
|
|
|
|
|
it 'allows MR to be merged' do
|
2016-04-27 18:34:42 +00:00
|
|
|
visit_merge_request(merge_request)
|
|
|
|
|
2017-05-17 18:25:13 +00:00
|
|
|
wait_for_requests
|
2017-05-09 04:15:34 +00:00
|
|
|
|
|
|
|
expect(page).to have_button 'Merge'
|
2016-04-27 18:34:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-07 11:01:34 +00:00
|
|
|
context 'when CI succeeded' do
|
2016-11-18 17:30:07 +00:00
|
|
|
given(:status) { :success }
|
2016-06-07 11:01:34 +00:00
|
|
|
|
|
|
|
it 'allows MR to be merged' do
|
2016-04-27 18:34:42 +00:00
|
|
|
visit_merge_request(merge_request)
|
|
|
|
|
2017-05-17 18:25:13 +00:00
|
|
|
wait_for_requests
|
2017-05-09 04:15:34 +00:00
|
|
|
|
|
|
|
expect(page).to have_button 'Merge'
|
2016-04-27 18:34:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def visit_merge_request(merge_request)
|
2017-07-06 16:20:50 +00:00
|
|
|
visit project_merge_request_path(merge_request.project, merge_request)
|
2016-04-27 18:34:42 +00:00
|
|
|
end
|
|
|
|
end
|