2019-07-31 22:56:46 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-05-09 12:01:36 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe ProtectedBranches::DestroyService do
|
2018-05-09 12:01:36 +05:30
|
|
|
let(:protected_branch) { create(:protected_branch) }
|
|
|
|
let(:project) { protected_branch.project }
|
2022-03-02 08:16:31 +05:30
|
|
|
let(:user) { project.first_owner }
|
2018-05-09 12:01:36 +05:30
|
|
|
|
|
|
|
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
|
2021-09-04 01:27:46 +05:30
|
|
|
policy = instance_double(ProtectedBranchPolicy, allowed?: false)
|
2018-05-09 12:01:36 +05:30
|
|
|
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
|