summaryrefslogtreecommitdiff
path: root/spec/controllers
diff options
context:
space:
mode:
authorFelipe Artur <felipefac@gmail.com>2017-11-30 16:00:09 -0200
committerFelipe Artur <felipefac@gmail.com>2017-12-05 12:54:10 -0200
commitf586dc0735545d96d73dd26ff182ddf2d50dd715 (patch)
treeaf3c7a732cf23b94033e071edcd73fe689714238 /spec/controllers
parent8f78ba554d8cc7ff90a0f1c98b6f641afbc5b4ae (diff)
downloadgitlab-ce-f586dc0735545d96d73dd26ff182ddf2d50dd715.tar.gz
Check if head_pipeline is correct before merging
Diffstat (limited to 'spec/controllers')
-rw-r--r--spec/controllers/projects/merge_requests_controller_spec.rb20
1 files changed, 16 insertions, 4 deletions
diff --git a/spec/controllers/projects/merge_requests_controller_spec.rb b/spec/controllers/projects/merge_requests_controller_spec.rb
index bfdad85c082..51d5d6a52b3 100644
--- a/spec/controllers/projects/merge_requests_controller_spec.rb
+++ b/spec/controllers/projects/merge_requests_controller_spec.rb
@@ -324,12 +324,12 @@ describe Projects::MergeRequestsController do
end
context 'when the pipeline succeeds is passed' do
- def merge_when_pipeline_succeeds
- post :merge, base_params.merge(sha: merge_request.diff_head_sha, merge_when_pipeline_succeeds: '1')
+ let!(:head_pipeline) do
+ create(:ci_empty_pipeline, project: project, sha: merge_request.diff_head_sha, ref: merge_request.source_branch, head_pipeline_of: merge_request)
end
- before do
- create(:ci_empty_pipeline, project: project, sha: merge_request.diff_head_sha, ref: merge_request.source_branch, head_pipeline_of: merge_request)
+ def merge_when_pipeline_succeeds
+ post :merge, base_params.merge(sha: merge_request.diff_head_sha, merge_when_pipeline_succeeds: '1')
end
it 'returns :merge_when_pipeline_succeeds' do
@@ -354,6 +354,18 @@ describe Projects::MergeRequestsController do
project.update_column(:only_allow_merge_if_pipeline_succeeds, true)
end
+ context 'and head pipeline is not the current one' do
+ before do
+ head_pipeline.update(sha: 'not_current_sha')
+ end
+
+ it 'returns :failed' do
+ merge_when_pipeline_succeeds
+
+ expect(json_response).to eq('status' => 'failed')
+ end
+ end
+
it 'returns :merge_when_pipeline_succeeds' do
merge_when_pipeline_succeeds