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
|
2017-04-03 12:10:58 -04:00
|
|
|
let(:project) { create(:project, :repository) }
|
|
|
|
let(:subject) { described_class.new(project, :branches) }
|
|
|
|
|
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
|
|
|
|
|
2017-04-03 12:10:58 -04:00
|
|
|
describe '#protectable_ref_names' do
|
2021-01-05 22:10:22 -05:00
|
|
|
context 'when project repository is not empty' do
|
|
|
|
before do
|
|
|
|
project.protected_branches.create(name: 'master')
|
|
|
|
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-04-03 12:10:58 -04:00
|
|
|
|
2021-01-05 22:10:22 -05:00
|
|
|
create(:protected_branch, name: 'feat*', project: project)
|
2017-04-03 12:10:58 -04:00
|
|
|
|
2021-01-05 22:10:22 -05:00
|
|
|
subject = described_class.new(project.reload, :branches)
|
|
|
|
|
|
|
|
expect(subject.protectable_ref_names).to include('feature')
|
|
|
|
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
|
|
|
|
2021-01-05 22:10:22 -05:00
|
|
|
it "returns empty list" do
|
|
|
|
subject = described_class.new(project, :branches)
|
2017-04-05 13:59:46 -04:00
|
|
|
|
2021-01-05 22:10:22 -05:00
|
|
|
expect(subject.protectable_ref_names).to be_empty
|
|
|
|
end
|
2017-04-03 12:10:58 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|