Fix pipeline reference existence check and add specs

This commit is contained in:
Grzegorz Bizon 2018-10-22 11:37:52 +02:00
parent 49d7c3b346
commit 5f412e3a87
2 changed files with 26 additions and 3 deletions

View file

@ -269,7 +269,7 @@ module Ci
end
def ref_exists?
project.repository.ref_exists?(self.ref)
project.repository.ref_exists?(git_ref)
end
##
@ -678,11 +678,11 @@ module Ci
def push_details
strong_memoize(:push_details) do
Gitlab::Git::Push.new(project, before_sha, sha, push_ref)
Gitlab::Git::Push.new(project, before_sha, sha, git_ref)
end
end
def push_ref
def git_ref
if branch?
Gitlab::Git::BRANCH_REF_PREFIX + ref.to_s
elsif tag?

View file

@ -779,6 +779,29 @@ describe Ci::Pipeline, :mailer do
end
end
describe 'ref_exists?' do
using RSpec::Parameterized::TableSyntax
let(:project) { create(:project, :repository) }
where(:tag, :ref, :result) do
false | 'master' | true
false | 'non-existent-branch' | false
true | 'v1.1.0' | true
true | 'non-existent-tag' | false
end
with_them do
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 'with non-empty project' do
let(:project) { create(:project, :repository) }