summaryrefslogtreecommitdiff
path: root/spec/models
diff options
context:
space:
mode:
authorKamil Trzciński <ayufan@ayufan.eu>2019-09-03 09:18:46 +0000
committerKamil Trzciński <ayufan@ayufan.eu>2019-09-03 09:18:46 +0000
commit6b7fe67adacb1402cadfb7d2b7eb4da03e06f149 (patch)
tree763a4719ae4c58cbd9b418e2816b8f7e6d5b1eab /spec/models
parent5fef9bd9f0a8a90b849e827f6c0b65e8fd77f3d7 (diff)
parent8c21610c79d2737c9cd728964f499d793e6a1279 (diff)
downloadgitlab-ce-6b7fe67adacb1402cadfb7d2b7eb4da03e06f149.tar.gz
Merge branch 'add-pipeline-type-key-in-pipeline-entity' into 'master'
Expose `name` and `merge_request_event_type` in serialized json and predefined variables See merge request gitlab-org/gitlab-ce!32323
Diffstat (limited to 'spec/models')
-rw-r--r--spec/models/ci/pipeline_spec.rb64
-rw-r--r--spec/models/merge_request_spec.rb34
2 files changed, 97 insertions, 1 deletions
diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb
index 7d84d094bdf..63ca383ac4b 100644
--- a/spec/models/ci/pipeline_spec.rb
+++ b/spec/models/ci/pipeline_spec.rb
@@ -323,6 +323,25 @@ describe Ci::Pipeline, :mailer do
end
end
+ describe '#merge_train_pipeline?' do
+ subject { pipeline.merge_train_pipeline? }
+
+ let!(:pipeline) do
+ create(:ci_pipeline, source: :merge_request_event, merge_request: merge_request, ref: ref, target_sha: 'xxx')
+ end
+
+ let(:merge_request) { create(:merge_request) }
+ let(:ref) { 'refs/merge-requests/1/train' }
+
+ it { is_expected.to be_truthy }
+
+ context 'when ref is merge ref' do
+ let(:ref) { 'refs/merge-requests/1/merge' }
+
+ it { is_expected.to be_falsy }
+ end
+ end
+
describe '#merge_request_ref?' do
subject { pipeline.merge_request_ref? }
@@ -333,6 +352,48 @@ describe Ci::Pipeline, :mailer do
end
end
+ describe '#merge_train_ref?' do
+ subject { pipeline.merge_train_ref? }
+
+ it 'calls Mergetrain#merge_train_ref?' do
+ expect(MergeRequest).to receive(:merge_train_ref?).with(pipeline.ref)
+
+ subject
+ end
+ end
+
+ describe '#merge_request_event_type' do
+ subject { pipeline.merge_request_event_type }
+
+ before do
+ allow(pipeline).to receive(:merge_request_event?) { true }
+ end
+
+ context 'when pipeline is merge train pipeline' do
+ before do
+ allow(pipeline).to receive(:merge_train_pipeline?) { true }
+ end
+
+ it { is_expected.to eq(:merge_train) }
+ end
+
+ context 'when pipeline is merge request pipeline' do
+ before do
+ allow(pipeline).to receive(:merge_request_pipeline?) { true }
+ end
+
+ it { is_expected.to eq(:merged_result) }
+ end
+
+ context 'when pipeline is detached merge request pipeline' do
+ before do
+ allow(pipeline).to receive(:detached_merge_request_pipeline?) { true }
+ end
+
+ it { is_expected.to eq(:detached) }
+ end
+ end
+
describe '#legacy_detached_merge_request_pipeline?' do
subject { pipeline.legacy_detached_merge_request_pipeline? }
@@ -782,7 +843,8 @@ describe Ci::Pipeline, :mailer do
'CI_MERGE_REQUEST_TITLE' => merge_request.title,
'CI_MERGE_REQUEST_ASSIGNEES' => merge_request.assignee_username_list,
'CI_MERGE_REQUEST_MILESTONE' => milestone.title,
- 'CI_MERGE_REQUEST_LABELS' => labels.map(&:title).join(','))
+ 'CI_MERGE_REQUEST_LABELS' => labels.map(&:title).join(','),
+ 'CI_MERGE_REQUEST_EVENT_TYPE' => pipeline.merge_request_event_type.to_s)
end
context 'when source project does not exist' do
diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb
index d344a6d0f0d..11234982dd4 100644
--- a/spec/models/merge_request_spec.rb
+++ b/spec/models/merge_request_spec.rb
@@ -3195,6 +3195,40 @@ describe MergeRequest do
end
end
+ describe '.merge_train_ref?' do
+ subject { described_class.merge_train_ref?(ref) }
+
+ context 'when ref is ref name of a branch' do
+ let(:ref) { 'feature' }
+
+ it { is_expected.to be_falsey }
+ end
+
+ context 'when ref is HEAD ref path of a branch' do
+ let(:ref) { 'refs/heads/feature' }
+
+ it { is_expected.to be_falsey }
+ end
+
+ context 'when ref is HEAD ref path of a merge request' do
+ let(:ref) { 'refs/merge-requests/1/head' }
+
+ it { is_expected.to be_falsey }
+ end
+
+ context 'when ref is merge ref path of a merge request' do
+ let(:ref) { 'refs/merge-requests/1/merge' }
+
+ it { is_expected.to be_falsey }
+ end
+
+ context 'when ref is train ref path of a merge request' do
+ let(:ref) { 'refs/merge-requests/1/train' }
+
+ it { is_expected.to be_truthy }
+ end
+ end
+
describe '#cleanup_refs' do
subject { merge_request.cleanup_refs(only: only) }