summaryrefslogtreecommitdiff
path: root/spec/models/protectable_dropdown_spec.rb
blob: 918c3078405f67a02199a8aecb26a1d5271d7035 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe ProtectableDropdown do
  let(:project) { create(:project, :repository) }
  let(:subject) { described_class.new(project, :branches) }

  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

  describe '#protectable_ref_names' do
    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')

        create(:protected_branch, name: 'feat*', project: project)

        subject = described_class.new(project.reload, :branches)

        expect(subject.protectable_ref_names).to include('feature')
      end
    end

    context 'when project repository is empty' do
      let(:project) { create(:project) }

      it "returns empty list" do
        subject = described_class.new(project, :branches)

        expect(subject.protectable_ref_names).to be_empty
      end
    end
  end
end