Commit d02e7226 authored by Mark Fletcher's avatar Mark Fletcher

Detect already enabled DeployKeys in EnableDeployKeyService

Ensures deploy keys can't be re-added, which causes a validation error
parent 03f13af5
......@@ -4,7 +4,10 @@ module Projects
key = accessible_keys.find_by(id: params[:key_id] || params[:id])
return unless key
project.deploy_keys << key
unless project.deploy_keys.include?(key)
project.deploy_keys << key
end
key
end
......
---
title: Detect already enabled DeployKeys in EnableDeployKeyService
merge_request:
author:
......@@ -21,6 +21,16 @@ describe Projects::EnableDeployKeyService, services: true do
end
end
context 'add the same key twice' do
before do
project.deploy_keys << deploy_key
end
it 'returns existing key' do
expect(service.execute).to eq(deploy_key)
end
end
def service
Projects::EnableDeployKeyService.new(project, user, params)
end
......
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