2019-04-11 12:17:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-24 11:05:04 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 15:08:50 +00:00
|
|
|
RSpec.describe ProtectedBranches::DestroyService do
|
2018-03-24 11:05:04 +00:00
|
|
|
let(:protected_branch) { create(:protected_branch) }
|
|
|
|
let(:project) { protected_branch.project }
|
2022-01-20 00:15:02 +00:00
|
|
|
let(:user) { project.first_owner }
|
2018-03-24 11:05:04 +00:00
|
|
|
|
|
|
|
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
|
2018-03-25 00:54:56 +00:00
|
|
|
|
|
|
|
context 'when a policy restricts rule deletion' do
|
|
|
|
before do
|
2021-06-16 18:10:35 +00:00
|
|
|
policy = instance_double(ProtectedBranchPolicy, allowed?: false)
|
2018-03-25 00:54:56 +00:00
|
|
|
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
|
2018-03-24 11:05:04 +00:00
|
|
|
end
|
|
|
|
end
|