debian-mirror-gitlab/spec/services/protected_branches/update_service_spec.rb

52 lines
1.6 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe ProtectedBranches::UpdateService do
2017-08-17 22:00:37 +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 }
2021-12-07 22:27:20 +05:30
let(:params) { { name: new_name } }
2017-08-17 22:00:37 +05:30
describe '#execute' do
2021-12-07 22:27:20 +05:30
let(:new_name) { 'new protected branch name' }
let(:result) { service.execute(protected_branch) }
2017-08-17 22:00:37 +05:30
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-05 19:09:49 +05:30
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 22:27:20 +05:30
2022-02-05 19:09:49 +05:30
subject(:service) { described_class.new(project, user, params) }
2021-12-07 22:27:20 +05:30
2022-02-05 19:09:49 +05:30
it 'updates a protected branch' do
expect(result.reload.name).to eq(new_name)
2021-12-07 22:27:20 +05:30
end
end
2017-08-17 22:00:37 +05:30
context 'without admin_project permissions' do
let(:user) { create(:user) }
it "raises error" do
2018-03-17 18:26:18 +05:30
expect { service.execute(protected_branch) }.to raise_error(Gitlab::Access::AccessDeniedError)
2017-08-17 22:00:37 +05:30
end
end
2018-05-09 12:01:36 +05:30
context 'when a policy restricts rule creation' 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 creation of the protected branch rule" do
expect { service.execute(protected_branch) }.to raise_error(Gitlab::Access::AccessDeniedError)
end
end
2017-08-17 22:00:37 +05:30
end
end