summaryrefslogtreecommitdiff
path: root/spec/services/protected_branches/destroy_service_spec.rb
blob: 4a391b6c25cc1a066338acc5d17515a3ef8efc86 (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
require 'spec_helper'

describe ProtectedBranches::DestroyService do
  let(:protected_branch) { create(:protected_branch) }
  let(:project) { protected_branch.project }
  let(:user) { project.owner }

  describe '#execute' do
    subject(:service) { described_class.new(project, user) }

    it 'destroys a protected branch' do
      service.execute(protected_branch)

      expect(protected_branch).to be_destroyed
    end

    context 'when a policy restricts rule deletion' do
      before do
        policy = instance_double(ProtectedBranchPolicy, can?: false)
        expect(ProtectedBranchPolicy).to receive(:new).and_return(policy)
      end

      it "prevents deletion of the protected branch rule" do
        expect do
          service.execute(protected_branch)
        end.to raise_error(Gitlab::Access::AccessDeniedError)
      end
    end
  end
end