Do not raise error when checking pipeline reference
Return from the `Ci::Pipeline#ref_exists?` in case when there is no repository present. This also fixes pipeline page feature specs by changing pipeline reference instead of stubbing `ref_exist?` method.
This commit is contained in:
parent
5f412e3a87
commit
680afb3d77
|
@ -270,6 +270,8 @@ module Ci
|
||||||
|
|
||||||
def ref_exists?
|
def ref_exists?
|
||||||
project.repository.ref_exists?(git_ref)
|
project.repository.ref_exists?(git_ref)
|
||||||
|
rescue Gitlab::Git::Repository::NoRepository
|
||||||
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
##
|
##
|
||||||
|
|
|
@ -241,9 +241,12 @@ describe 'Pipeline', :js do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context 'with deleted branch' do
|
context 'when pipeline ref does not exist in repository anymore' do
|
||||||
before do
|
let(:pipeline) do
|
||||||
allow(pipeline).to receive(:ref_exists?).and_return(false)
|
create(:ci_empty_pipeline, project: project,
|
||||||
|
ref: 'non-existent',
|
||||||
|
sha: project.commit.id,
|
||||||
|
user: user)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'does not render link to the pipeline ref' do
|
it 'does not render link to the pipeline ref' do
|
||||||
|
|
|
@ -780,24 +780,36 @@ describe Ci::Pipeline, :mailer do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'ref_exists?' do
|
describe 'ref_exists?' do
|
||||||
using RSpec::Parameterized::TableSyntax
|
context 'when repository exists' do
|
||||||
|
using RSpec::Parameterized::TableSyntax
|
||||||
|
|
||||||
let(:project) { create(:project, :repository) }
|
let(:project) { create(:project, :repository) }
|
||||||
|
|
||||||
where(:tag, :ref, :result) do
|
where(:tag, :ref, :result) do
|
||||||
false | 'master' | true
|
false | 'master' | true
|
||||||
false | 'non-existent-branch' | false
|
false | 'non-existent-branch' | false
|
||||||
true | 'v1.1.0' | true
|
true | 'v1.1.0' | true
|
||||||
true | 'non-existent-tag' | false
|
true | 'non-existent-tag' | false
|
||||||
end
|
|
||||||
|
|
||||||
with_them do
|
|
||||||
let(:pipeline) do
|
|
||||||
create(:ci_empty_pipeline, project: project, tag: tag, ref: ref)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
it "correctly detects ref" do
|
with_them do
|
||||||
expect(pipeline.ref_exists?).to be result
|
let(:pipeline) do
|
||||||
|
create(:ci_empty_pipeline, project: project, tag: tag, ref: ref)
|
||||||
|
end
|
||||||
|
|
||||||
|
it "correctly detects ref" do
|
||||||
|
expect(pipeline.ref_exists?).to be result
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'when repository does not exist' do
|
||||||
|
let(:pipeline) do
|
||||||
|
create(:ci_empty_pipeline, project: project, ref: 'master')
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'always returns false' do
|
||||||
|
expect(pipeline.ref_exists?).to eq false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue