Commit f1857590 authored by Etienne Baqué's avatar Etienne Baqué

Fixed deploy token creation

Fixed case when a deploy token is created without scope.
Updated rspec accordingly.
Did a bit of refactoring for the DeployToken create services classes.
parent fbf2cde3
......@@ -43,7 +43,7 @@ module Groups
end
def create_deploy_token
result = Projects::DeployTokens::CreateService.new(@group, current_user, deploy_token_params).execute
result = Groups::DeployTokens::CreateService.new(@group, current_user, deploy_token_params).execute
@new_deploy_token = result[:deploy_token]
if result[:status] == :success
......
......@@ -14,4 +14,12 @@ module DeployTokenMethods
deploy_token.destroy
end
def create_deploy_token_payload_for(deploy_token)
if deploy_token.persisted?
success(deploy_token: deploy_token, http_status: :created)
else
error(deploy_token.errors.full_messages.to_sentence, :bad_request).merge(deploy_token: deploy_token)
end
end
end
......@@ -8,11 +8,7 @@ module Groups
def execute
deploy_token = create_deploy_token_for(@group, params)
if deploy_token.persisted?
success(deploy_token: deploy_token, http_status: :created)
else
error(deploy_token.errors.full_messages.to_sentence, :bad_request)
end
create_deploy_token_payload_for(deploy_token)
end
end
end
......
......@@ -8,11 +8,7 @@ module Projects
def execute
deploy_token = create_deploy_token_for(@project, params)
if deploy_token.persisted?
success(deploy_token: deploy_token, http_status: :created)
else
error(deploy_token.errors.full_messages.to_sentence, :bad_request)
end
create_deploy_token_payload_for(deploy_token)
end
end
end
......
# frozen_string_literal: true
RSpec.shared_examples 'a created deploy token' do
let(:read_repository) { '1' }
let(:deploy_token_params) do
{
name: 'deployer_token',
expires_at: 1.month.from_now.to_date.to_s,
username: 'deployer',
read_repository: '1',
read_repository: read_repository,
deploy_token_type: deploy_token_type
}
end
......@@ -19,4 +20,15 @@ RSpec.shared_examples 'a created deploy token' do
expect(response).to have_gitlab_http_status(:ok)
expect(response).to render_template(:show)
end
context 'when no scope is selected' do
let(:read_repository) { '0' }
it 'creates a variable with a errored deploy token' do
expect { create_deploy_token }.not_to change { DeployToken.active.count }
expect(assigns(:new_deploy_token)).to be_a(DeployToken)
expect(assigns(:new_deploy_token).errors.full_messages.first).to eq('Scopes can\'t be blank')
end
end
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