Commit 5f412e3a authored by Grzegorz Bizon's avatar Grzegorz Bizon

Fix pipeline reference existence check and add specs

parent 49d7c3b3
...@@ -269,7 +269,7 @@ module Ci ...@@ -269,7 +269,7 @@ module Ci
end end
def ref_exists? def ref_exists?
project.repository.ref_exists?(self.ref) project.repository.ref_exists?(git_ref)
end end
## ##
...@@ -678,11 +678,11 @@ module Ci ...@@ -678,11 +678,11 @@ module Ci
def push_details def push_details
strong_memoize(:push_details) do 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
end end
def push_ref def git_ref
if branch? if branch?
Gitlab::Git::BRANCH_REF_PREFIX + ref.to_s Gitlab::Git::BRANCH_REF_PREFIX + ref.to_s
elsif tag? elsif tag?
......
...@@ -779,6 +779,29 @@ describe Ci::Pipeline, :mailer do ...@@ -779,6 +779,29 @@ describe Ci::Pipeline, :mailer do
end end
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 context 'with non-empty project' do
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
......
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