From 9da3ae70923fdf35e4850676cc1d238e5d63ea16 Mon Sep 17 00:00:00 2001 From: Hiroyuki Sato Date: Sun, 20 Jan 2019 11:41:11 +0900 Subject: Don't create merge request pipeline without commits --- spec/services/ci/create_pipeline_service_spec.rb | 9 +++++++++ spec/services/merge_requests/refresh_service_spec.rb | 8 ++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) (limited to 'spec/services') diff --git a/spec/services/ci/create_pipeline_service_spec.rb b/spec/services/ci/create_pipeline_service_spec.rb index 8497e90bd8b..be6bdc21b81 100644 --- a/spec/services/ci/create_pipeline_service_spec.rb +++ b/spec/services/ci/create_pipeline_service_spec.rb @@ -736,6 +736,15 @@ describe Ci::CreatePipelineService do end end + context 'when there are no commits between source branch and target branch' do + let(:ref_name) { 'refs/heads/not-merged-branch' } + + it 'does not create a merge request pipeline' do + expect(pipeline).not_to be_persisted + expect(pipeline.errors[:merge_request]).to eq(["must have commits"]) + end + end + context 'when merge request is created from a forked project' do let(:merge_request) do create(:merge_request, diff --git a/spec/services/merge_requests/refresh_service_spec.rb b/spec/services/merge_requests/refresh_service_spec.rb index 1169ed5f9f2..57b8e71c2d5 100644 --- a/spec/services/merge_requests/refresh_service_spec.rb +++ b/spec/services/merge_requests/refresh_service_spec.rb @@ -150,11 +150,15 @@ describe MergeRequests::RefreshService do } end - it 'create merge request pipeline' do + it 'create merge request pipeline with commits' do expect { subject } .to change { @merge_request.merge_request_pipelines.count }.by(1) .and change { @fork_merge_request.merge_request_pipelines.count }.by(1) - .and change { @another_merge_request.merge_request_pipelines.count }.by(1) + .and change { @another_merge_request.merge_request_pipelines.count }.by(0) + + expect(@merge_request.has_commits?).to be true + expect(@fork_merge_request.has_commits?).to be true + expect(@another_merge_request.has_commits?).to be false end context "when branch pipeline was created before a merge request pipline has been created" do -- cgit v1.2.1 From 74946c19b4056052da4f5a9059ae73b2c0771d03 Mon Sep 17 00:00:00 2001 From: Hiroyuki Sato Date: Mon, 28 Jan 2019 14:54:33 +0900 Subject: Move validation logic to service layer --- spec/services/ci/create_pipeline_service_spec.rb | 9 --------- spec/services/merge_requests/create_service_spec.rb | 18 ++++++++++++++++++ spec/services/merge_requests/refresh_service_spec.rb | 6 +++--- 3 files changed, 21 insertions(+), 12 deletions(-) (limited to 'spec/services') diff --git a/spec/services/ci/create_pipeline_service_spec.rb b/spec/services/ci/create_pipeline_service_spec.rb index be6bdc21b81..8497e90bd8b 100644 --- a/spec/services/ci/create_pipeline_service_spec.rb +++ b/spec/services/ci/create_pipeline_service_spec.rb @@ -736,15 +736,6 @@ describe Ci::CreatePipelineService do end end - context 'when there are no commits between source branch and target branch' do - let(:ref_name) { 'refs/heads/not-merged-branch' } - - it 'does not create a merge request pipeline' do - expect(pipeline).not_to be_persisted - expect(pipeline.errors[:merge_request]).to eq(["must have commits"]) - end - end - context 'when merge request is created from a forked project' do let(:merge_request) do create(:merge_request, diff --git a/spec/services/merge_requests/create_service_spec.rb b/spec/services/merge_requests/create_service_spec.rb index 308f99dc0da..723cc860d0c 100644 --- a/spec/services/merge_requests/create_service_spec.rb +++ b/spec/services/merge_requests/create_service_spec.rb @@ -226,6 +226,24 @@ describe MergeRequests::CreateService do end end + context 'when there are no commits between source branch and target branch' do + let(:opts) do + { + title: 'Awesome merge_request', + description: 'please fix', + source_branch: 'not-merged-branch', + target_branch: 'master' + } + end + + it 'does not create a merge request pipeline' do + expect(merge_request).to be_persisted + + merge_request.reload + expect(merge_request.merge_request_pipelines.count).to eq(0) + end + end + context "when .gitlab-ci.yml does not have merge_requests keywords" do let(:config) do { diff --git a/spec/services/merge_requests/refresh_service_spec.rb b/spec/services/merge_requests/refresh_service_spec.rb index 57b8e71c2d5..9e9dc5a576c 100644 --- a/spec/services/merge_requests/refresh_service_spec.rb +++ b/spec/services/merge_requests/refresh_service_spec.rb @@ -156,9 +156,9 @@ describe MergeRequests::RefreshService do .and change { @fork_merge_request.merge_request_pipelines.count }.by(1) .and change { @another_merge_request.merge_request_pipelines.count }.by(0) - expect(@merge_request.has_commits?).to be true - expect(@fork_merge_request.has_commits?).to be true - expect(@another_merge_request.has_commits?).to be false + expect(@merge_request.has_commits?).to be_truthy + expect(@fork_merge_request.has_commits?).to be_truthy + expect(@another_merge_request.has_commits?).to be_falsy end context "when branch pipeline was created before a merge request pipline has been created" do -- cgit v1.2.1 From 348e346d521b3d7375b23a2dd1def73096649f39 Mon Sep 17 00:00:00 2001 From: Hiroyuki Sato Date: Tue, 5 Feb 2019 16:31:30 +0900 Subject: Fix false-positive spec --- .../services/merge_requests/create_service_spec.rb | 36 +++++++++++----------- 1 file changed, 18 insertions(+), 18 deletions(-) (limited to 'spec/services') diff --git a/spec/services/merge_requests/create_service_spec.rb b/spec/services/merge_requests/create_service_spec.rb index 723cc860d0c..53022fb9eb7 100644 --- a/spec/services/merge_requests/create_service_spec.rb +++ b/spec/services/merge_requests/create_service_spec.rb @@ -197,6 +197,24 @@ describe MergeRequests::CreateService do expect(merge_request.actual_head_pipeline).to be_merge_request end + context 'when there are no commits between source branch and target branch' do + let(:opts) do + { + title: 'Awesome merge_request', + description: 'please fix', + source_branch: 'not-merged-branch', + target_branch: 'master' + } + end + + it 'does not create a merge request pipeline' do + expect(merge_request).to be_persisted + + merge_request.reload + expect(merge_request.merge_request_pipelines.count).to eq(0) + end + end + context "when branch pipeline was created before a merge request pipline has been created" do before do create(:ci_pipeline, project: merge_request.source_project, @@ -226,24 +244,6 @@ describe MergeRequests::CreateService do end end - context 'when there are no commits between source branch and target branch' do - let(:opts) do - { - title: 'Awesome merge_request', - description: 'please fix', - source_branch: 'not-merged-branch', - target_branch: 'master' - } - end - - it 'does not create a merge request pipeline' do - expect(merge_request).to be_persisted - - merge_request.reload - expect(merge_request.merge_request_pipelines.count).to eq(0) - end - end - context "when .gitlab-ci.yml does not have merge_requests keywords" do let(:config) do { -- cgit v1.2.1