Commit ee028785 authored by Stan Hu's avatar Stan Hu

Merge branch 'mc/bug/nil-take' into 'master'

Fix nil take regression

Closes #65725

See merge request gitlab-org/gitlab-ce!31554
parents 2fd73269 56876070
......@@ -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
......
......@@ -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,6 +1167,9 @@ describe Project do
end
end
context 'with a matching pipeline' do
let!(:pipeline) { create_pipeline(project) }
context 'with explicit sha' do
subject { project.pipeline_for('master', pipeline.sha) }
......@@ -1189,17 +1191,22 @@ describe Project do
end
end
context 'when there is no matching pipeline' do
subject { project.pipeline_for('master') }
it { is_expected.to be_nil }
end
end
describe '#pipelines_for' do
let(:project) { create(:project, :repository) }
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
end
describe '#builds_enabled' do
let(:project) { create(:project) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment