2019-04-11 08:17:24 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-05 13:59:46 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 11:08:50 -04:00
|
|
|
RSpec.describe ProtectedBranches::UpdateService do
|
2017-04-05 13:59:46 -04:00
|
|
|
let(:protected_branch) { create(:protected_branch) }
|
|
|
|
let(:project) { protected_branch.project }
|
|
|
|
let(:user) { project.owner }
|
|
|
|
let(:params) { { name: 'new protected branch name' } }
|
|
|
|
|
|
|
|
describe '#execute' do
|
|
|
|
subject(:service) { described_class.new(project, user, params) }
|
|
|
|
|
|
|
|
it 'updates a protected branch' do
|
|
|
|
result = service.execute(protected_branch)
|
|
|
|
|
|
|
|
expect(result.reload.name).to eq(params[:name])
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'without admin_project permissions' do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
it "raises error" do
|
2017-08-09 05:52:22 -04:00
|
|
|
expect { service.execute(protected_branch) }.to raise_error(Gitlab::Access::AccessDeniedError)
|
2017-04-05 13:59:46 -04:00
|
|
|
end
|
|
|
|
end
|
2018-03-24 20:54:56 -04:00
|
|
|
|
|
|
|
context 'when a policy restricts rule creation' do
|
|
|
|
before do
|
2021-06-16 14:10:35 -04:00
|
|
|
policy = instance_double(ProtectedBranchPolicy, allowed?: false)
|
2018-03-24 20:54:56 -04:00
|
|
|
expect(ProtectedBranchPolicy).to receive(:new).and_return(policy)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "prevents creation of the protected branch rule" do
|
|
|
|
expect { service.execute(protected_branch) }.to raise_error(Gitlab::Access::AccessDeniedError)
|
|
|
|
end
|
|
|
|
end
|
2017-04-05 13:59:46 -04:00
|
|
|
end
|
|
|
|
end
|