Make Projects::DeployKeysController EE-ready

Signed-off-by: Rémy Coutable <remy@rymai.me>
This commit is contained in:
Rémy Coutable 2018-12-18 17:40:05 +01:00
parent becfb66213
commit fa7ed15df6
No known key found for this signature in database
GPG Key ID: 98DFFD1C0C62B70B
3 changed files with 37 additions and 3 deletions

View File

@ -24,7 +24,7 @@ class Projects::DeployKeysController < Projects::ApplicationController
end
def create
@key = DeployKeys::CreateService.new(current_user, create_params).execute
@key = DeployKeys::CreateService.new(current_user, create_params).execute(project: @project)
unless @key.valid?
flash[:alert] = @key.errors.full_messages.join(', ').html_safe

View File

@ -2,7 +2,7 @@
module DeployKeys
class CreateService < Keys::BaseService
def execute
def execute(project: nil)
DeployKey.create(params.merge(user: user))
end
end

View File

@ -16,7 +16,7 @@ describe Projects::DeployKeysController do
end
context 'when html requested' do
it 'redirects to blob' do
it 'redirects to project settings with the correct anchor' do
get :index, params: params
expect(response).to redirect_to(project_settings_repository_path(project, anchor: 'js-deploy-keys-settings'))
@ -60,6 +60,40 @@ describe Projects::DeployKeysController do
end
end
describe 'POST create' do
def create_params(title = 'my-key')
{
namespace_id: project.namespace.path,
project_id: project.path,
deploy_key: {
title: title,
key: attributes_for(:deploy_key)[:key],
deploy_keys_projects_attributes: { '0' => { can_push: '1' } }
}
}
end
it 'creates a new deploy key for the project' do
expect { post :create, params: create_params }.to change(project.deploy_keys, :count).by(1)
expect(response).to redirect_to(project_settings_repository_path(project, anchor: 'js-deploy-keys-settings'))
end
it 'redirects to project settings with the correct anchor' do
post :create, params: create_params
expect(response).to redirect_to(project_settings_repository_path(project, anchor: 'js-deploy-keys-settings'))
end
context 'when the deploy key is invalid' do
it 'shows an alert with the validations errors' do
post :create, params: create_params(nil)
expect(flash[:alert]).to eq("Title can't be blank, Deploy keys projects deploy key title can't be blank")
end
end
end
describe '/enable/:id' do
let(:deploy_key) { create(:deploy_key) }
let(:project2) { create(:project) }