gitlab-org--gitlab-foss/spec/models/concerns/has_ref_spec.rb

80 lines
1.9 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
require 'spec_helper'
describe HasRef do
describe '#branch?' do
2018-12-08 14:39:11 -05:00
let(:build) { create(:ci_build) }
2018-12-08 14:39:11 -05:00
subject { build.branch? }
context 'is not a tag' do
before do
2018-12-08 14:39:11 -05:00
build.tag = false
end
it 'return true when tag is set to false' do
is_expected.to be_truthy
end
context 'when it was triggered by merge request' do
let(:merge_request) { create(:merge_request, :with_detached_merge_request_pipeline) }
let(:pipeline) { merge_request.merge_request_pipelines.first }
let(:build) { create(:ci_build, pipeline: pipeline) }
it 'returns false' do
is_expected.to be_falsy
end
end
end
context 'is not a tag' do
before do
2018-12-08 14:39:11 -05:00
build.tag = true
end
it 'return false when tag is set to true' do
is_expected.to be_falsey
end
end
end
2018-11-15 15:28:17 -05:00
describe '#git_ref' do
2018-12-08 14:39:11 -05:00
subject { build.git_ref }
2018-11-15 15:28:17 -05:00
context 'when tag is true' do
2018-12-08 14:39:11 -05:00
let(:build) { create(:ci_build, tag: true) }
2018-11-15 15:28:17 -05: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 14:39:11 -05:00
let(:build) { create(:ci_build, tag: false) }
2018-11-15 15:28:17 -05: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 14:39:11 -05:00
let(:build) { create(:ci_build, tag: nil) }
2018-11-15 15:28:17 -05:00
it 'returns a branch ref' do
is_expected.to start_with(Gitlab::Git::BRANCH_REF_PREFIX)
end
end
context 'when it is triggered by a merge request' do
let(:merge_request) { create(:merge_request, :with_detached_merge_request_pipeline) }
let(:pipeline) { merge_request.merge_request_pipelines.first }
let(:build) { create(:ci_build, tag: false, pipeline: pipeline) }
it 'returns nil' do
is_expected.to be_nil
end
end
2018-11-15 15:28:17 -05:00
end
end