Commit a163c371 authored by Sashi's avatar Sashi Committed by Matthias Käppler

Fix uninitialized constant in update protected branch

This change fixes the uninitialized constant exception
when a protected branch is updated while creating security
policy project.
parent 5bcd609d
......@@ -34,7 +34,7 @@ module Security
}
if protected_branch.present?
ProtectedBranch::UpdateService
ProtectedBranches::UpdateService
.new(policy_project, current_user, params)
.execute(protected_branch)
return
......
......@@ -29,6 +29,48 @@ RSpec.describe Security::SecurityOrchestrationPolicies::ProjectCreateService do
end
end
context 'when protected branch already exists' do
let_it_be(:project) { create(:project) }
let_it_be(:current_user) { project.owner }
let_it_be(:maintainer) { create(:user) }
before do
project.add_maintainer(maintainer)
allow_next_instance_of(Project) do |instance|
allow(instance).to receive_message_chain(:protected_branches, :find_by_name).and_return([ProtectedBranch.new])
end
protected_branch_service = instance_spy(ProtectedBranches::UpdateService)
allow(ProtectedBranches::UpdateService).to receive(:new).and_return(protected_branch_service)
end
it 'updates protected branch' do
service.execute
expect(ProtectedBranches::UpdateService).to have_received(:new)
end
end
context 'when protected branch does not exist' do
let_it_be(:project) { create(:project) }
let_it_be(:current_user) { project.owner }
let_it_be(:maintainer) { create(:user) }
before do
project.add_maintainer(maintainer)
protected_branch_service = instance_spy(ProtectedBranches::CreateService)
allow(ProtectedBranches::CreateService).to receive(:new).and_return(protected_branch_service)
end
it 'creates protected branch' do
service.execute
expect(ProtectedBranches::CreateService).to have_received(:new)
end
end
context 'when adding users to security policy project fails' do
let_it_be(:project) { create(:project) }
let_it_be(:current_user) { project.owner }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment