2019-03-30 03:23:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-03 12:10:58 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 02:09:01 -04:00
|
|
|
RSpec.describe ProtectableDropdown do
|
2022-01-13 13:16:51 -05:00
|
|
|
subject(:dropdown) { described_class.new(project, ref_type) }
|
|
|
|
|
2017-04-03 12:10:58 -04:00
|
|
|
let(:project) { create(:project, :repository) }
|
|
|
|
|
2017-08-10 12:39:26 -04:00
|
|
|
describe 'initialize' do
|
|
|
|
it 'raises ArgumentError for invalid ref type' do
|
|
|
|
expect { described_class.new(double, :foo) }
|
|
|
|
.to raise_error(ArgumentError, "invalid ref type `foo`")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-01-13 13:16:51 -05:00
|
|
|
shared_examples 'protectable_ref_names' do
|
2021-01-05 22:10:22 -05:00
|
|
|
context 'when project repository is not empty' do
|
2022-01-13 13:16:51 -05:00
|
|
|
it 'includes elements matching a protected ref wildcard' do
|
|
|
|
is_expected.to include(matching_ref)
|
2021-01-05 22:10:22 -05:00
|
|
|
|
2022-01-13 13:16:51 -05:00
|
|
|
factory = ref_type == :branches ? :protected_branch : :protected_tag
|
2017-04-03 12:10:58 -04:00
|
|
|
|
2022-01-13 13:16:51 -05:00
|
|
|
create(factory, name: "#{matching_ref[0]}*", project: project)
|
2017-04-03 12:10:58 -04:00
|
|
|
|
2022-01-13 13:16:51 -05:00
|
|
|
subject = described_class.new(project.reload, ref_type)
|
2021-01-05 22:10:22 -05:00
|
|
|
|
2022-01-13 13:16:51 -05:00
|
|
|
expect(subject.protectable_ref_names).to include(matching_ref)
|
2021-01-05 22:10:22 -05:00
|
|
|
end
|
|
|
|
end
|
2017-04-03 12:10:58 -04:00
|
|
|
|
2021-01-05 22:10:22 -05:00
|
|
|
context 'when project repository is empty' do
|
|
|
|
let(:project) { create(:project) }
|
2017-04-03 12:10:58 -04:00
|
|
|
|
2022-01-13 13:16:51 -05:00
|
|
|
it 'returns empty list' do
|
|
|
|
is_expected.to be_empty
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#protectable_ref_names' do
|
|
|
|
subject { dropdown.protectable_ref_names }
|
|
|
|
|
|
|
|
context 'for branches' do
|
|
|
|
let(:ref_type) { :branches }
|
|
|
|
let(:matching_ref) { 'feature' }
|
2017-04-05 13:59:46 -04:00
|
|
|
|
2022-01-13 13:16:51 -05:00
|
|
|
before do
|
|
|
|
create(:protected_branch, project: project, name: 'master')
|
2021-01-05 22:10:22 -05:00
|
|
|
end
|
2022-01-13 13:16:51 -05:00
|
|
|
|
|
|
|
it { is_expected.to include(matching_ref) }
|
|
|
|
it { is_expected.not_to include('master') }
|
|
|
|
|
|
|
|
it_behaves_like 'protectable_ref_names'
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for tags' do
|
|
|
|
let(:ref_type) { :tags }
|
|
|
|
let(:matching_ref) { 'v1.0.0' }
|
|
|
|
|
|
|
|
before do
|
|
|
|
create(:protected_tag, project: project, name: 'v1.1.0')
|
|
|
|
end
|
|
|
|
|
|
|
|
it { is_expected.to include(matching_ref) }
|
|
|
|
it { is_expected.not_to include('v1.1.0') }
|
|
|
|
|
|
|
|
it_behaves_like 'protectable_ref_names'
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#hash' do
|
|
|
|
subject { dropdown.hash }
|
|
|
|
|
|
|
|
context 'for branches' do
|
|
|
|
let(:ref_type) { :branches }
|
|
|
|
|
|
|
|
it { is_expected.to include(id: 'feature', text: 'feature', title: 'feature') }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'for tags' do
|
|
|
|
let(:ref_type) { :tags }
|
|
|
|
|
|
|
|
it { is_expected.to include(id: 'v1.0.0', text: 'v1.0.0', title: 'v1.0.0') }
|
2017-04-03 12:10:58 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|