Merge branch 'ce-reduce-deploy_keys_controller-diff-with-ce' into 'master'

Make Projects::DeployKeysController EE-ready

See merge request gitlab-org/gitlab-ce!23911
This commit is contained in:
Robert Speicher 2018-12-19 19:23:55 +00:00
commit 832235395d
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) }