summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatija Čupić <matteeyah@gmail.com>2019-07-23 21:21:05 +0200
committerMatija Čupić <matteeyah@gmail.com>2019-07-23 21:22:43 +0200
commit1eab06571496c1b7950dc081435fa21058b614c8 (patch)
treeb6cfd7b41fa02467fd1bb74a9d660f6c2f4df3ff
parent7cee6139c07db7ba4fd6febf74c24dbfaee8e59d (diff)
downloadgitlab-ce-1eab06571496c1b7950dc081435fa21058b614c8.tar.gz
Add specs for latest_successful methods for SHAs
-rw-r--r--spec/models/ci/pipeline_spec.rb13
-rw-r--r--spec/models/project_spec.rb55
2 files changed, 68 insertions, 0 deletions
diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb
index e24bbc39761..e3f699d9ad3 100644
--- a/spec/models/ci/pipeline_spec.rb
+++ b/spec/models/ci/pipeline_spec.rb
@@ -1812,6 +1812,19 @@ describe Ci::Pipeline, :mailer do
end
end
+ describe '.latest_successful_for_sha' do
+ include_context 'with some outdated pipelines'
+
+ let!(:latest_successful_pipeline) do
+ create_pipeline(:success, 'ref', 'awesomesha', project)
+ end
+
+ it 'returns the latest successful pipeline' do
+ expect(described_class.latest_successful_for_sha('awesomesha'))
+ .to eq(latest_successful_pipeline)
+ end
+ end
+
describe '.latest_successful_for_refs' do
include_context 'with some outdated pipelines'
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index 9a083eee05e..e88c6a60fec 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -2074,6 +2074,61 @@ describe Project do
end
end
+ describe '#latest_successful_build_for_sha' do
+ let(:project) { create(:project, :repository) }
+ let(:pipeline) { create_pipeline(project) }
+
+ context 'with many builds' do
+ it 'gives the latest builds from latest pipeline' do
+ pipeline1 = create_pipeline(project)
+ pipeline2 = create_pipeline(project)
+ create_build(pipeline1, 'test')
+ create_build(pipeline1, 'test2')
+ build1_p2 = create_build(pipeline2, 'test')
+ create_build(pipeline2, 'test2')
+
+ expect(project.latest_successful_build_for_sha(build1_p2.name))
+ .to eq(build1_p2)
+ end
+ end
+
+ context 'with succeeded pipeline' do
+ let!(:build) { create_build }
+
+ context 'standalone pipeline' do
+ it 'returns builds for ref for default_branch' do
+ expect(project.latest_successful_build_for_sha(build.name))
+ .to eq(build)
+ end
+
+ it 'returns empty relation if the build cannot be found' do
+ expect(project.latest_successful_build_for_sha('TAIL'))
+ .to be_nil
+ end
+ end
+
+ context 'with some pending pipeline' do
+ before do
+ create_build(create_pipeline(project, 'pending'))
+ end
+
+ it 'gives the latest build from latest pipeline' do
+ expect(project.latest_successful_build_for_sha(build.name))
+ .to eq(build)
+ end
+ end
+ end
+
+ context 'with pending pipeline' do
+ it 'returns empty relation' do
+ pipeline.update(status: 'pending')
+ pending_build = create_build(pipeline)
+
+ expect(project.latest_successful_build_for_sha(pending_build.name)).to be_nil
+ end
+ end
+ end
+
describe '#latest_successful_build_for!' do
let(:project) { create(:project, :repository) }
let(:pipeline) { create_pipeline(project) }