2019-04-11 12:17:24 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-04-05 17:59:46 +00:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 15:08:50 +00:00
|
|
|
RSpec.describe ProtectedBranches::UpdateService do
|
2017-04-05 17:59:46 +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 }
|
2021-12-07 03:12:22 +00:00
|
|
|
let(:params) { { name: new_name } }
|
2017-04-05 17:59:46 +00:00
|
|
|
|
|
|
|
describe '#execute' do
|
2021-12-07 03:12:22 +00:00
|
|
|
let(:new_name) { 'new protected branch name' }
|
|
|
|
let(:result) { service.execute(protected_branch) }
|
|
|
|
|
2017-04-05 17:59:46 +00:00
|
|
|
subject(:service) { described_class.new(project, user, params) }
|
|
|
|
|
|
|
|
it 'updates a protected branch' do
|
|
|
|
expect(result.reload.name).to eq(params[:name])
|
|
|
|
end
|
|
|
|
|
2022-02-04 00:13:53 +00:00
|
|
|
context 'when updating name of a protected branch to one that contains HTML tags' do
|
|
|
|
let(:new_name) { 'foo<b>bar<\b>' }
|
|
|
|
let(:result) { service.execute(protected_branch) }
|
2021-12-07 03:12:22 +00:00
|
|
|
|
2022-02-04 00:13:53 +00:00
|
|
|
subject(:service) { described_class.new(project, user, params) }
|
2021-12-07 03:12:22 +00:00
|
|
|
|
2022-02-04 00:13:53 +00:00
|
|
|
it 'updates a protected branch' do
|
|
|
|
expect(result.reload.name).to eq(new_name)
|
2021-12-07 03:12:22 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-04-05 17:59:46 +00:00
|
|
|
context 'without admin_project permissions' do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
it "raises error" do
|
2017-08-09 09:52:22 +00:00
|
|
|
expect { service.execute(protected_branch) }.to raise_error(Gitlab::Access::AccessDeniedError)
|
2017-04-05 17:59:46 +00:00
|
|
|
end
|
|
|
|
end
|
2018-03-25 00:54:56 +00:00
|
|
|
|
|
|
|
context 'when a policy restricts rule creation' 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 creation of the protected branch rule" do
|
|
|
|
expect { service.execute(protected_branch) }.to raise_error(Gitlab::Access::AccessDeniedError)
|
|
|
|
end
|
|
|
|
end
|
2017-04-05 17:59:46 +00:00
|
|
|
end
|
|
|
|
end
|