Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/models/protectable_dropdown_spec.rb')
-rw-r--r--spec/models/protectable_dropdown_spec.rb74
1 files changed, 58 insertions, 16 deletions
diff --git a/spec/models/protectable_dropdown_spec.rb b/spec/models/protectable_dropdown_spec.rb
index ab3f455fe63..a256f9e0ab1 100644
--- a/spec/models/protectable_dropdown_spec.rb
+++ b/spec/models/protectable_dropdown_spec.rb
@@ -3,8 +3,9 @@
require 'spec_helper'
RSpec.describe ProtectableDropdown do
+ subject(:dropdown) { described_class.new(project, ref_type) }
+
let(:project) { create(:project, :repository) }
- let(:subject) { described_class.new(project, :branches) }
describe 'initialize' do
it 'raises ArgumentError for invalid ref type' do
@@ -13,34 +14,75 @@ RSpec.describe ProtectableDropdown do
end
end
- describe '#protectable_ref_names' do
+ shared_examples 'protectable_ref_names' do
context 'when project repository is not empty' do
- before do
- create(:protected_branch, project: project, name: 'master')
- end
-
- it { expect(subject.protectable_ref_names).to include('feature') }
- it { expect(subject.protectable_ref_names).not_to include('master') }
+ it 'includes elements matching a protected ref wildcard' do
+ is_expected.to include(matching_ref)
- it "includes branches matching a protected branch wildcard" do
- expect(subject.protectable_ref_names).to include('feature')
+ factory = ref_type == :branches ? :protected_branch : :protected_tag
- create(:protected_branch, name: 'feat*', project: project)
+ create(factory, name: "#{matching_ref[0]}*", project: project)
- subject = described_class.new(project.reload, :branches)
+ subject = described_class.new(project.reload, ref_type)
- expect(subject.protectable_ref_names).to include('feature')
+ expect(subject.protectable_ref_names).to include(matching_ref)
end
end
context 'when project repository is empty' do
let(:project) { create(:project) }
- it "returns empty list" do
- subject = described_class.new(project, :branches)
+ 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' }
- expect(subject.protectable_ref_names).to be_empty
+ before do
+ create(:protected_branch, project: project, name: 'master')
end
+
+ 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') }
end
end
end