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/project_spec.rb')
-rw-r--r--spec/models/project_spec.rb37
1 files changed, 37 insertions, 0 deletions
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index 5b4b9c516a0..67f64822184 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -2027,6 +2027,43 @@ describe Project do
end
end
+ describe '#latest_pipeline_for_ref' do
+ let(:project) { create(:project, :repository) }
+ let(:second_branch) { project.repository.branches[2] }
+
+ let!(:pipeline_for_default_branch) do
+ create(:ci_empty_pipeline, project: project, sha: project.commit.id,
+ ref: project.default_branch)
+ end
+ let!(:pipeline_for_second_branch) do
+ create(:ci_empty_pipeline, project: project, sha: second_branch.target,
+ ref: second_branch.name)
+ end
+
+ before do
+ create(:ci_empty_pipeline, project: project, sha: project.commit.parent.id,
+ ref: project.default_branch)
+ end
+
+ context 'default repository branch' do
+ subject { project.latest_pipeline_for_ref(project.default_branch) }
+
+ it { is_expected.to eq(pipeline_for_default_branch) }
+ end
+
+ context 'provided ref' do
+ subject { project.latest_pipeline_for_ref(second_branch.name) }
+
+ it { is_expected.to eq(pipeline_for_second_branch) }
+ end
+
+ context 'bad ref' do
+ subject { project.latest_pipeline_for_ref(SecureRandom.uuid) }
+
+ it { is_expected.to be_nil }
+ end
+ end
+
describe '#latest_successful_build_for_sha' do
let(:project) { create(:project, :repository) }
let(:pipeline) { create_pipeline(project) }