Commit fa7ed15d authored by Rémy Coutable's avatar Rémy Coutable

Make Projects::DeployKeysController EE-ready

Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent becfb662
...@@ -24,7 +24,7 @@ class Projects::DeployKeysController < Projects::ApplicationController ...@@ -24,7 +24,7 @@ class Projects::DeployKeysController < Projects::ApplicationController
end end
def create 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? unless @key.valid?
flash[:alert] = @key.errors.full_messages.join(', ').html_safe flash[:alert] = @key.errors.full_messages.join(', ').html_safe
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
module DeployKeys module DeployKeys
class CreateService < Keys::BaseService class CreateService < Keys::BaseService
def execute def execute(project: nil)
DeployKey.create(params.merge(user: user)) DeployKey.create(params.merge(user: user))
end end
end end
......
...@@ -16,7 +16,7 @@ describe Projects::DeployKeysController do ...@@ -16,7 +16,7 @@ describe Projects::DeployKeysController do
end end
context 'when html requested' do context 'when html requested' do
it 'redirects to blob' do it 'redirects to project settings with the correct anchor' do
get :index, params: params get :index, params: params
expect(response).to redirect_to(project_settings_repository_path(project, anchor: 'js-deploy-keys-settings')) expect(response).to redirect_to(project_settings_repository_path(project, anchor: 'js-deploy-keys-settings'))
...@@ -60,6 +60,40 @@ describe Projects::DeployKeysController do ...@@ -60,6 +60,40 @@ describe Projects::DeployKeysController do
end end
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 describe '/enable/:id' do
let(:deploy_key) { create(:deploy_key) } let(:deploy_key) { create(:deploy_key) }
let(:project2) { create(:project) } let(:project2) { create(:project) }
......
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