summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatija Čupić <matteeyah@gmail.com>2019-08-06 23:58:17 +0200
committerMatija Čupić <matteeyah@gmail.com>2019-08-07 00:13:03 +0200
commit56876070aa8784cabf59dd71433458b0ebeb077e (patch)
tree06ab548d5c7815f4a1296c0d39b4c7fabf9c9424
parent2fd73269ef7e7415380478fd50d8288f6899c6f6 (diff)
downloadgitlab-ce-mc/bug/nil-take.tar.gz
Fix nil take regressionmc/bug/nil-take
-rw-r--r--app/models/project.rb9
-rw-r--r--spec/models/project_spec.rb35
2 files changed, 25 insertions, 19 deletions
diff --git a/app/models/project.rb b/app/models/project.rb
index 33f1077e982..44b6e5a532c 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -1487,6 +1487,9 @@ class Project < ApplicationRecord
end
def pipeline_for(ref, sha = nil, id = nil)
+ sha ||= commit(ref).try(:sha)
+ return unless sha
+
if id.present?
pipelines_for(ref, sha).find_by(id: id)
else
@@ -1494,11 +1497,7 @@ class Project < ApplicationRecord
end
end
- def pipelines_for(ref, sha = nil)
- sha ||= commit(ref).try(:sha)
-
- return unless sha
-
+ def pipelines_for(ref, sha)
ci_pipelines.order(id: :desc).where(sha: sha, ref: ref)
end
diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb
index 157103123ad..2e6c81d0a7e 100644
--- a/spec/models/project_spec.rb
+++ b/spec/models/project_spec.rb
@@ -1156,7 +1156,6 @@ describe Project do
describe '#pipeline_for' do
let(:project) { create(:project, :repository) }
- let!(:pipeline) { create_pipeline(project) }
shared_examples 'giving the correct pipeline' do
it { is_expected.to eq(pipeline) }
@@ -1168,24 +1167,34 @@ describe Project do
end
end
- context 'with explicit sha' do
- subject { project.pipeline_for('master', pipeline.sha) }
+ context 'with a matching pipeline' do
+ let!(:pipeline) { create_pipeline(project) }
+
+ context 'with explicit sha' do
+ subject { project.pipeline_for('master', pipeline.sha) }
+
+ it_behaves_like 'giving the correct pipeline'
+
+ context 'with supplied id' do
+ let!(:other_pipeline) { create_pipeline(project) }
- it_behaves_like 'giving the correct pipeline'
+ subject { project.pipeline_for('master', pipeline.sha, other_pipeline.id) }
- context 'with supplied id' do
- let!(:other_pipeline) { create_pipeline(project) }
+ it { is_expected.to eq(other_pipeline) }
+ end
+ end
- subject { project.pipeline_for('master', pipeline.sha, other_pipeline.id) }
+ context 'with implicit sha' do
+ subject { project.pipeline_for('master') }
- it { is_expected.to eq(other_pipeline) }
+ it_behaves_like 'giving the correct pipeline'
end
end
- context 'with implicit sha' do
+ context 'when there is no matching pipeline' do
subject { project.pipeline_for('master') }
- it_behaves_like 'giving the correct pipeline'
+ it { is_expected.to be_nil }
end
end
@@ -1194,11 +1203,9 @@ describe Project do
let!(:pipeline) { create_pipeline(project) }
let!(:other_pipeline) { create_pipeline(project) }
- context 'with implicit sha' do
- subject { project.pipelines_for('master') }
+ subject { project.pipelines_for(project.default_branch, project.commit.sha) }
- it { is_expected.to contain_exactly(pipeline, other_pipeline) }
- end
+ it { is_expected.to contain_exactly(pipeline, other_pipeline) }
end
describe '#builds_enabled' do