2018-11-10 13:34:53 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe HasRef do
|
|
|
|
describe '#branch?' do
|
2018-12-08 19:39:11 +00:00
|
|
|
let(:build) { create(:ci_build) }
|
2018-11-10 13:34:53 +00:00
|
|
|
|
2018-12-08 19:39:11 +00:00
|
|
|
subject { build.branch? }
|
2018-11-10 13:34:53 +00:00
|
|
|
|
|
|
|
context 'is not a tag' do
|
|
|
|
before do
|
2018-12-08 19:39:11 +00:00
|
|
|
build.tag = false
|
2018-11-10 13:34:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'return true when tag is set to false' do
|
|
|
|
is_expected.to be_truthy
|
|
|
|
end
|
2019-02-28 09:15:32 +00:00
|
|
|
|
|
|
|
context 'when it was triggered by merge request' do
|
2019-03-07 07:33:13 +00:00
|
|
|
let(:merge_request) { create(:merge_request, :with_detached_merge_request_pipeline) }
|
2019-03-27 08:46:29 +00:00
|
|
|
let(:pipeline) { merge_request.pipelines_for_merge_request.first }
|
2019-02-28 09:15:32 +00:00
|
|
|
let(:build) { create(:ci_build, pipeline: pipeline) }
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
is_expected.to be_falsy
|
|
|
|
end
|
|
|
|
end
|
2018-11-10 13:34:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'is not a tag' do
|
|
|
|
before do
|
2018-12-08 19:39:11 +00:00
|
|
|
build.tag = true
|
2018-11-10 13:34:53 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'return false when tag is set to true' do
|
|
|
|
is_expected.to be_falsey
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2018-11-15 20:28:17 +00:00
|
|
|
|
|
|
|
describe '#git_ref' do
|
2018-12-08 19:39:11 +00:00
|
|
|
subject { build.git_ref }
|
2018-11-15 20:28:17 +00:00
|
|
|
|
|
|
|
context 'when tag is true' do
|
2018-12-08 19:39:11 +00:00
|
|
|
let(:build) { create(:ci_build, tag: true) }
|
2018-11-15 20:28:17 +00:00
|
|
|
|
|
|
|
it 'returns a tag ref' do
|
|
|
|
is_expected.to start_with(Gitlab::Git::TAG_REF_PREFIX)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when tag is false' do
|
2018-12-08 19:39:11 +00:00
|
|
|
let(:build) { create(:ci_build, tag: false) }
|
2018-11-15 20:28:17 +00:00
|
|
|
|
|
|
|
it 'returns a branch ref' do
|
|
|
|
is_expected.to start_with(Gitlab::Git::BRANCH_REF_PREFIX)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when tag is nil' do
|
2018-12-08 19:39:11 +00:00
|
|
|
let(:build) { create(:ci_build, tag: nil) }
|
2018-11-15 20:28:17 +00:00
|
|
|
|
|
|
|
it 'returns a branch ref' do
|
|
|
|
is_expected.to start_with(Gitlab::Git::BRANCH_REF_PREFIX)
|
|
|
|
end
|
|
|
|
end
|
2019-02-28 09:15:32 +00:00
|
|
|
|
|
|
|
context 'when it is triggered by a merge request' do
|
2019-03-07 07:33:13 +00:00
|
|
|
let(:merge_request) { create(:merge_request, :with_detached_merge_request_pipeline) }
|
2019-03-27 08:46:29 +00:00
|
|
|
let(:pipeline) { merge_request.pipelines_for_merge_request.first }
|
2019-02-28 09:15:32 +00:00
|
|
|
let(:build) { create(:ci_build, tag: false, pipeline: pipeline) }
|
|
|
|
|
|
|
|
it 'returns nil' do
|
|
|
|
is_expected.to be_nil
|
|
|
|
end
|
|
|
|
end
|
2018-11-15 20:28:17 +00:00
|
|
|
end
|
2018-11-10 13:34:53 +00:00
|
|
|
end
|