2016-04-27 18:34:42 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2016-06-07 11:01:34 +00:00
|
|
|
feature 'Only allow merge requests to be merged if the build succeeds', feature: 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
|
2016-06-07 11:01:34 +00:00
|
|
|
login_as 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
|
|
|
|
|
2016-06-07 11:01:34 +00:00
|
|
|
context 'project does not have CI enabled' do
|
|
|
|
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
|
|
|
|
|
|
|
expect(page).to have_button 'Accept Merge Request'
|
2016-04-27 18:34:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-07 11:01:34 +00:00
|
|
|
context 'when project has CI enabled' 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,
|
|
|
|
status: status)
|
|
|
|
end
|
2016-04-27 18:34:42 +00:00
|
|
|
|
2016-06-07 11:01:34 +00:00
|
|
|
context 'when merge requests can only be merged if the build succeeds' do
|
2016-04-27 18:34:42 +00:00
|
|
|
before do
|
|
|
|
project.update_attribute(:only_allow_merge_if_build_succeeds, true)
|
|
|
|
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)
|
|
|
|
|
2016-11-25 10:59:12 +00:00
|
|
|
expect(page).to have_button 'Merge When Pipeline Succeeds'
|
2016-06-07 11:01:34 +00:00
|
|
|
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)
|
|
|
|
|
|
|
|
expect(page).not_to have_button 'Accept Merge Request'
|
|
|
|
expect(page).to have_content('Please retry the build or push a new commit to fix the failure.')
|
|
|
|
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)
|
|
|
|
|
2016-06-07 11:01:34 +00:00
|
|
|
expect(page).not_to have_button 'Accept Merge Request'
|
|
|
|
expect(page).to have_content('Please retry the build 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)
|
|
|
|
|
|
|
|
expect(page).to have_button 'Accept Merge Request'
|
|
|
|
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)
|
|
|
|
|
2016-06-07 11:01:34 +00:00
|
|
|
expect(page).to have_button 'Accept Merge Request'
|
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
|
|
|
|
project.update_attribute(:only_allow_merge_if_build_succeeds, false)
|
|
|
|
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 'allows MR to be merged immediately', js: true do
|
2016-04-27 18:34:42 +00:00
|
|
|
visit_merge_request(merge_request)
|
|
|
|
|
2016-11-25 10:59:12 +00:00
|
|
|
expect(page).to have_button 'Merge When Pipeline Succeeds'
|
2016-04-27 18:34:42 +00:00
|
|
|
|
2016-06-07 11:01:34 +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)
|
|
|
|
|
2016-06-07 11:01:34 +00:00
|
|
|
expect(page).to have_button 'Accept Merge Request'
|
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)
|
|
|
|
|
2016-06-07 11:01:34 +00:00
|
|
|
expect(page).to have_button 'Accept Merge Request'
|
2016-04-27 18:34:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def visit_merge_request(merge_request)
|
|
|
|
visit namespace_project_merge_request_path(merge_request.project.namespace, merge_request.project, merge_request)
|
|
|
|
end
|
|
|
|
end
|