summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-10-22 11:37:52 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2018-10-22 11:37:52 +0200
commit5f412e3a87d1e9444bbef6475a2cd3304f541f7d (patch)
tree4e2218a691a3ccd08223174ddabbb0789a21623f
parent49d7c3b3461442a60d06a26c8cc971205afa3642 (diff)
downloadgitlab-ce-5f412e3a87d1e9444bbef6475a2cd3304f541f7d.tar.gz
Fix pipeline reference existence check and add specs
-rw-r--r--app/models/ci/pipeline.rb6
-rw-r--r--spec/models/ci/pipeline_spec.rb23
2 files changed, 26 insertions, 3 deletions
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb
index c53b14bd406..c93f0e0cd55 100644
--- a/app/models/ci/pipeline.rb
+++ b/app/models/ci/pipeline.rb
@@ -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?
diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb
index 3b01b39ecab..06f000a7118 100644
--- a/spec/models/ci/pipeline_spec.rb
+++ b/spec/models/ci/pipeline_spec.rb
@@ -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) }