diff options
author | Matija Čupić <matteeyah@gmail.com> | 2018-11-15 21:28:17 +0100 |
---|---|---|
committer | Matija Čupić <matteeyah@gmail.com> | 2018-12-08 19:28:34 +0100 |
commit | 837ab8c5d83243db8efe1cec1c6e001d1cbeb43f (patch) | |
tree | cf2dc96a8f526f428090e36f2bf6c93b1f236b5c | |
parent | 2edc02143b2d361275fb97ce2904a58e7dc8ff38 (diff) | |
download | gitlab-ce-837ab8c5d83243db8efe1cec1c6e001d1cbeb43f.tar.gz |
Make HasRef#git_ref public
-rw-r--r-- | app/models/concerns/has_ref.rb | 4 | ||||
-rw-r--r-- | spec/models/concerns/has_ref_spec.rb | 28 |
2 files changed, 28 insertions, 4 deletions
diff --git a/app/models/concerns/has_ref.rb b/app/models/concerns/has_ref.rb index 79816841f7f..d7089294efc 100644 --- a/app/models/concerns/has_ref.rb +++ b/app/models/concerns/has_ref.rb @@ -7,15 +7,11 @@ module HasRef !tag? end - private - def git_ref if branch? Gitlab::Git::BRANCH_REF_PREFIX + ref.to_s elsif tag? Gitlab::Git::TAG_REF_PREFIX + ref.to_s - else - raise ArgumentError, 'Invalid pipeline type!' end end end diff --git a/spec/models/concerns/has_ref_spec.rb b/spec/models/concerns/has_ref_spec.rb index ec3cf9a8580..14db197dfe0 100644 --- a/spec/models/concerns/has_ref_spec.rb +++ b/spec/models/concerns/has_ref_spec.rb @@ -28,4 +28,32 @@ describe HasRef do end end end + + describe '#git_ref' do + subject { pipeline.git_ref } + + context 'when tag is true' do + let(:pipeline) { create(:ci_pipeline, tag: true) } + + it 'returns a tag ref' do + is_expected.to start_with(Gitlab::Git::TAG_REF_PREFIX) + end + end + + context 'when tag is false' do + let(:pipeline) { create(:ci_pipeline, tag: false) } + + it 'returns a branch ref' do + is_expected.to start_with(Gitlab::Git::BRANCH_REF_PREFIX) + end + end + + context 'when tag is nil' do + let(:pipeline) { create(:ci_pipeline, tag: nil) } + + it 'returns a branch ref' do + is_expected.to start_with(Gitlab::Git::BRANCH_REF_PREFIX) + end + end + end end |