Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/ci/pipeline_spec.rb')
-rw-r--r--spec/models/ci/pipeline_spec.rb291
1 files changed, 40 insertions, 251 deletions
diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb
index d24cf3d2115..3f9e882ea52 100644
--- a/spec/models/ci/pipeline_spec.rb
+++ b/spec/models/ci/pipeline_spec.rb
@@ -75,71 +75,6 @@ describe Ci::Pipeline, :mailer do
end
end
- describe '.sort_by_merge_request_pipelines' do
- subject { described_class.sort_by_merge_request_pipelines }
-
- context 'when branch pipelines exist' do
- let!(:branch_pipeline_1) { create(:ci_pipeline, source: :push) }
- let!(:branch_pipeline_2) { create(:ci_pipeline, source: :push) }
-
- it 'returns pipelines order by id' do
- expect(subject).to eq([branch_pipeline_2,
- branch_pipeline_1])
- end
- end
-
- context 'when merge request pipelines exist' do
- let!(:merge_request_pipeline_1) do
- create(:ci_pipeline, source: :merge_request_event, merge_request: merge_request)
- end
-
- let!(:merge_request_pipeline_2) do
- create(:ci_pipeline, source: :merge_request_event, merge_request: merge_request)
- end
-
- let(:merge_request) do
- create(:merge_request,
- source_project: project,
- source_branch: 'feature',
- target_project: project,
- target_branch: 'master')
- end
-
- it 'returns pipelines order by id' do
- expect(subject).to eq([merge_request_pipeline_2,
- merge_request_pipeline_1])
- end
- end
-
- context 'when both branch pipeline and merge request pipeline exist' do
- let!(:branch_pipeline_1) { create(:ci_pipeline, source: :push) }
- let!(:branch_pipeline_2) { create(:ci_pipeline, source: :push) }
-
- let!(:merge_request_pipeline_1) do
- create(:ci_pipeline, source: :merge_request_event, merge_request: merge_request)
- end
-
- let!(:merge_request_pipeline_2) do
- create(:ci_pipeline, source: :merge_request_event, merge_request: merge_request)
- end
-
- let(:merge_request) do
- create(:merge_request,
- source_project: project,
- source_branch: 'feature',
- target_project: project,
- target_branch: 'master')
- end
-
- it 'returns merge request pipeline first' do
- expect(subject).to eq([merge_request_pipeline_2,
- merge_request_pipeline_1,
- branch_pipeline_2,
- branch_pipeline_1])
- end
- end
- end
-
describe '.for_sha' do
subject { described_class.for_sha(sha) }
@@ -226,39 +161,6 @@ describe Ci::Pipeline, :mailer do
end
end
- describe '.detached_merge_request_pipelines' do
- subject { described_class.detached_merge_request_pipelines(merge_request, sha) }
-
- let!(:pipeline) do
- create(:ci_pipeline, source: :merge_request_event, merge_request: merge_request, sha: merge_request.diff_head_sha)
- end
-
- let(:merge_request) { create(:merge_request) }
- let(:sha) { merge_request.diff_head_sha }
-
- it 'returns detached merge request pipelines' do
- is_expected.to eq([pipeline])
- end
-
- context 'when sha does not exist' do
- let(:sha) { 'abc' }
-
- it 'returns empty array' do
- is_expected.to be_empty
- end
- end
-
- context 'when pipeline is merge request pipeline' do
- let!(:pipeline) do
- create(:ci_pipeline, source: :merge_request_event, merge_request: merge_request, source_sha: merge_request.diff_head_sha)
- end
-
- it 'returns empty array' do
- is_expected.to be_empty
- end
- end
- end
-
describe '#detached_merge_request_pipeline?' do
subject { pipeline.detached_merge_request_pipeline? }
@@ -278,39 +180,6 @@ describe Ci::Pipeline, :mailer do
end
end
- describe '.merge_request_pipelines' do
- subject { described_class.merge_request_pipelines(merge_request, source_sha) }
-
- let!(:pipeline) do
- create(:ci_pipeline, source: :merge_request_event, merge_request: merge_request, source_sha: merge_request.diff_head_sha)
- end
-
- let(:merge_request) { create(:merge_request) }
- let(:source_sha) { merge_request.diff_head_sha }
-
- it 'returns merge pipelines' do
- is_expected.to eq([pipeline])
- end
-
- context 'when source sha is empty' do
- let(:source_sha) { nil }
-
- it 'returns empty array' do
- is_expected.to be_empty
- end
- end
-
- context 'when pipeline is detached merge request pipeline' do
- let!(:pipeline) do
- create(:ci_pipeline, source: :merge_request_event, merge_request: merge_request, sha: merge_request.diff_head_sha)
- end
-
- it 'returns empty array' do
- is_expected.to be_empty
- end
- end
- end
-
describe '#merge_request_pipeline?' do
subject { pipeline.merge_request_pipeline? }
@@ -330,25 +199,6 @@ 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? }
@@ -359,43 +209,19 @@ 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
+ let(:pipeline) { merge_request.all_pipelines.last }
context 'when pipeline is merge request pipeline' do
- before do
- allow(pipeline).to receive(:merge_request_pipeline?) { true }
- end
+ let(:merge_request) { create(:merge_request, :with_merge_request_pipeline) }
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
+ let(:merge_request) { create(:merge_request, :with_detached_merge_request_pipeline) }
it { is_expected.to eq(:detached) }
end
@@ -499,50 +325,6 @@ describe Ci::Pipeline, :mailer do
end
end
- describe '.triggered_for_branch' do
- subject { described_class.triggered_for_branch(ref) }
-
- let(:project) { create(:project, :repository) }
- let(:ref) { 'feature' }
- let!(:pipeline) { create(:ci_pipeline, ref: ref) }
-
- it 'returns the pipeline' do
- is_expected.to eq([pipeline])
- end
-
- context 'when sha is not specified' do
- it 'returns the pipeline' do
- expect(described_class.triggered_for_branch(ref)).to eq([pipeline])
- end
- end
-
- context 'when pipeline is triggered for tag' do
- let(:ref) { 'v1.1.0' }
- let!(:pipeline) { create(:ci_pipeline, ref: ref, tag: true) }
-
- it 'does not return the pipeline' do
- is_expected.to be_empty
- end
- end
-
- context 'when pipeline is triggered for merge_request' do
- let!(:merge_request) do
- create(:merge_request,
- :with_merge_request_pipeline,
- source_project: project,
- source_branch: ref,
- target_project: project,
- target_branch: 'master')
- end
-
- let(:pipeline) { merge_request.pipelines_for_merge_request.first }
-
- it 'does not return the pipeline' do
- is_expected.to be_empty
- end
- end
- end
-
describe '.with_reports' do
subject { described_class.with_reports(Ci::JobArtifact.test_reports) }
@@ -808,13 +590,25 @@ describe Ci::Pipeline, :mailer do
it 'includes all predefined variables in a valid order' do
keys = subject.map { |variable| variable[:key] }
- expect(keys).to eq %w[CI_PIPELINE_IID
- CI_CONFIG_PATH
- CI_PIPELINE_SOURCE
- CI_COMMIT_MESSAGE
- CI_COMMIT_TITLE
- CI_COMMIT_DESCRIPTION
- CI_COMMIT_REF_PROTECTED]
+ expect(keys).to eq %w[
+ CI_PIPELINE_IID
+ CI_PIPELINE_SOURCE
+ CI_CONFIG_PATH
+ CI_COMMIT_SHA
+ CI_COMMIT_SHORT_SHA
+ CI_COMMIT_BEFORE_SHA
+ CI_COMMIT_REF_NAME
+ CI_COMMIT_REF_SLUG
+ CI_COMMIT_BRANCH
+ CI_COMMIT_MESSAGE
+ CI_COMMIT_TITLE
+ CI_COMMIT_DESCRIPTION
+ CI_COMMIT_REF_PROTECTED
+ CI_BUILD_REF
+ CI_BUILD_BEFORE_SHA
+ CI_BUILD_REF_NAME
+ CI_BUILD_REF_SLUG
+ ]
end
context 'when source is merge request' do
@@ -1045,7 +839,9 @@ describe Ci::Pipeline, :mailer do
stage_idx: 0,
status: 'success')
- pipeline.process!
+ Ci::ProcessPipelineService
+ .new(pipeline)
+ .execute
end
it 'ignores the previous state' do
@@ -1930,17 +1726,6 @@ describe Ci::Pipeline, :mailer do
end
end
- describe '.latest_for_shas' do
- let(:sha) { 'abc' }
-
- it 'returns latest pipeline for sha' do
- create(:ci_pipeline, sha: sha)
- pipeline2 = create(:ci_pipeline, sha: sha)
-
- expect(described_class.latest_for_shas(sha)).to contain_exactly(pipeline2)
- end
- end
-
describe '.latest_successful_ids_per_project' do
let(:projects) { create_list(:project, 2) }
let!(:pipeline1) { create(:ci_pipeline, :success, project: projects[0]) }
@@ -2110,7 +1895,7 @@ describe Ci::Pipeline, :mailer do
let(:pipeline) { create(:ci_pipeline, status: :created) }
it 'returns detailed status for created pipeline' do
- expect(subject.text).to eq 'created'
+ expect(subject.text).to eq s_('CiStatusText|created')
end
end
@@ -2118,7 +1903,7 @@ describe Ci::Pipeline, :mailer do
let(:pipeline) { create(:ci_pipeline, status: :pending) }
it 'returns detailed status for pending pipeline' do
- expect(subject.text).to eq 'pending'
+ expect(subject.text).to eq s_('CiStatusText|pending')
end
end
@@ -2126,7 +1911,7 @@ describe Ci::Pipeline, :mailer do
let(:pipeline) { create(:ci_pipeline, status: :running) }
it 'returns detailed status for running pipeline' do
- expect(subject.text).to eq 'running'
+ expect(subject.text).to eq s_('CiStatus|running')
end
end
@@ -2134,7 +1919,7 @@ describe Ci::Pipeline, :mailer do
let(:pipeline) { create(:ci_pipeline, status: :success) }
it 'returns detailed status for successful pipeline' do
- expect(subject.text).to eq 'passed'
+ expect(subject.text).to eq s_('CiStatusText|passed')
end
end
@@ -2142,7 +1927,7 @@ describe Ci::Pipeline, :mailer do
let(:pipeline) { create(:ci_pipeline, status: :failed) }
it 'returns detailed status for failed pipeline' do
- expect(subject.text).to eq 'failed'
+ expect(subject.text).to eq s_('CiStatusText|failed')
end
end
@@ -2150,7 +1935,7 @@ describe Ci::Pipeline, :mailer do
let(:pipeline) { create(:ci_pipeline, status: :canceled) }
it 'returns detailed status for canceled pipeline' do
- expect(subject.text).to eq 'canceled'
+ expect(subject.text).to eq s_('CiStatusText|canceled')
end
end
@@ -2158,7 +1943,7 @@ describe Ci::Pipeline, :mailer do
let(:pipeline) { create(:ci_pipeline, status: :skipped) }
it 'returns detailed status for skipped pipeline' do
- expect(subject.text).to eq 'skipped'
+ expect(subject.text).to eq s_('CiStatusText|skipped')
end
end
@@ -2166,7 +1951,7 @@ describe Ci::Pipeline, :mailer do
let(:pipeline) { create(:ci_pipeline, status: :manual) }
it 'returns detailed status for blocked pipeline' do
- expect(subject.text).to eq 'blocked'
+ expect(subject.text).to eq s_('CiStatusText|blocked')
end
end
@@ -2178,7 +1963,7 @@ describe Ci::Pipeline, :mailer do
end
it 'retruns detailed status for successful pipeline with warnings' do
- expect(subject.label).to eq 'passed with warnings'
+ expect(subject.label).to eq(s_('CiStatusLabel|passed with warnings'))
end
end
end
@@ -2472,7 +2257,9 @@ describe Ci::Pipeline, :mailer do
let(:pipeline) { create(:ci_empty_pipeline, status: 'created', project: project, ref: 'master', sha: 'a288a022a53a5a944fae87bcec6efc87b7061808') }
it "returns merge requests whose `diff_head_sha` matches the pipeline's SHA" do
- allow_any_instance_of(MergeRequest).to receive(:diff_head_sha) { 'a288a022a53a5a944fae87bcec6efc87b7061808' }
+ allow_next_instance_of(MergeRequest) do |instance|
+ allow(instance).to receive(:diff_head_sha) { 'a288a022a53a5a944fae87bcec6efc87b7061808' }
+ end
merge_request = create(:merge_request, source_project: project, head_pipeline: pipeline, source_branch: pipeline.ref)
expect(pipeline.merge_requests_as_head_pipeline).to eq([merge_request])
@@ -2486,7 +2273,9 @@ describe Ci::Pipeline, :mailer do
it "doesn't return merge requests whose `diff_head_sha` doesn't match the pipeline's SHA" do
create(:merge_request, source_project: project, source_branch: pipeline.ref)
- allow_any_instance_of(MergeRequest).to receive(:diff_head_sha) { '97de212e80737a608d939f648d959671fb0a0142b' }
+ allow_next_instance_of(MergeRequest) do |instance|
+ allow(instance).to receive(:diff_head_sha) { '97de212e80737a608d939f648d959671fb0a0142b' }
+ end
expect(pipeline.merge_requests_as_head_pipeline).to be_empty
end