2019-07-07 11:18:12 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe ProtectableDropdown do
|
2022-03-02 08:16:31 +05:30
|
|
|
subject(:dropdown) { described_class.new(project, ref_type) }
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:project) { create(:project, :repository) }
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
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-03-02 08:16:31 +05:30
|
|
|
shared_examples 'protectable_ref_names' do
|
2021-03-08 18:12:59 +05:30
|
|
|
context 'when project repository is not empty' do
|
2022-03-02 08:16:31 +05:30
|
|
|
it 'includes elements matching a protected ref wildcard' do
|
|
|
|
is_expected.to include(matching_ref)
|
2021-03-08 18:12:59 +05:30
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
factory = ref_type == :branches ? :protected_branch : :protected_tag
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
create(factory, name: "#{matching_ref[0]}*", project: project)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
subject = described_class.new(project.reload, ref_type)
|
2021-03-08 18:12:59 +05:30
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
expect(subject.protectable_ref_names).to include(matching_ref)
|
2021-03-08 18:12:59 +05:30
|
|
|
end
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
context 'when project repository is empty' do
|
|
|
|
let(:project) { create(:project) }
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
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-08-17 22:00:37 +05:30
|
|
|
|
2022-03-02 08:16:31 +05:30
|
|
|
before do
|
|
|
|
create(:protected_branch, project: project, name: 'master')
|
2021-03-08 18:12:59 +05:30
|
|
|
end
|
2022-03-02 08:16:31 +05:30
|
|
|
|
|
|
|
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-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|