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
|
2017-08-17 22:00:37 +05:30
|
|
|
let(:project) { create(:project, :repository) }
|
|
|
|
let(:subject) { described_class.new(project, :branches) }
|
|
|
|
|
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
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
describe '#protectable_ref_names' do
|
2021-03-08 18:12:59 +05:30
|
|
|
context 'when project repository is not empty' do
|
|
|
|
before do
|
2021-12-11 22:18:48 +05:30
|
|
|
create(:protected_branch, project: project, name: 'master')
|
2021-03-08 18:12:59 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(subject.protectable_ref_names).to include('feature') }
|
|
|
|
it { expect(subject.protectable_ref_names).not_to include('master') }
|
|
|
|
|
|
|
|
it "includes branches matching a protected branch wildcard" do
|
|
|
|
expect(subject.protectable_ref_names).to include('feature')
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
create(:protected_branch, name: 'feat*', project: project)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
subject = described_class.new(project.reload, :branches)
|
|
|
|
|
|
|
|
expect(subject.protectable_ref_names).to include('feature')
|
|
|
|
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
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
it "returns empty list" do
|
|
|
|
subject = described_class.new(project, :branches)
|
2017-08-17 22:00:37 +05:30
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
expect(subject.protectable_ref_names).to be_empty
|
|
|
|
end
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|