Commit cd05aef4 authored by Doug Stull's avatar Doug Stull

Merge branch 'jswain_combined_registration_validation' into 'master'

Combined Registration validations and defaults

See merge request gitlab-org/gitlab!71347
parents 11248104 e0af07e7
......@@ -22,7 +22,7 @@ module Registrations
@group = if group_id = params[:group][:id]
Group.find_by_id(group_id)
else
Groups::CreateService.new(current_user, group_params).execute
Groups::CreateService.new(current_user, modified_group_params).execute
end
if @group.persisted?
......@@ -56,7 +56,7 @@ module Registrations
end
def import
@group = Groups::CreateService.new(current_user, group_params).execute
@group = Groups::CreateService.new(current_user, modified_group_params).execute
if @group.persisted?
combined_registration_experiment.track(:create_group, namespace: @group)
......@@ -77,5 +77,15 @@ module Registrations
def project_params
params.require(:project).permit(project_params_attributes).merge(namespace_id: @group.id)
end
def modified_group_params
group_name = params.dig(:group, :name)
if group_name.present? && params.dig(:group, :path).blank?
group_params.compact_blank.with_defaults(path: Namespace.clean_path(group_name))
else
group_params
end
end
end
end
......@@ -8,8 +8,8 @@
= f.label :setup_for_company, setup_for_company_label_text, class: 'label-bold'
.gl-display-flex.gl-flex-direction-column.gl-lg-flex-direction-row
.gl-flex-grow-1
= f.radio_button :setup_for_company, true, class: 'js-setup-for-company'
= f.radio_button :setup_for_company, true, class: 'js-setup-for-company', required: true
= f.label :setup_for_company, _('My company or team'), class: 'normal', value: 'true'
.gl-flex-grow-1
= f.radio_button :setup_for_company, false, class: 'js-setup-for-me'
= f.radio_button :setup_for_company, false, class: 'js-setup-for-me', required: true
= f.label :setup_for_company, _('Just me'), class: 'normal', value: 'false'
......@@ -83,6 +83,14 @@ RSpec.describe Registrations::GroupsProjectsController, :experiment do
end
end
context 'when there is no suggested path based from the name' do
let(:group_params) { { name: '⛄⛄⛄', path: '' } }
it 'creates a group' do
expect { subject }.to change { Group.count }.by(1)
end
end
context 'when the group cannot be created' do
let(:group_params) { { name: '', path: '' } }
......@@ -241,6 +249,15 @@ RSpec.describe Registrations::GroupsProjectsController, :experiment do
it { is_expected.to render_template(:new) }
end
context 'when there is no suggested path based from the group name' do
let(:group_params) { { name: '⛄⛄⛄', path: '' } }
it 'creates a group, and redirects' do
expect { subject }.to change { Group.count }.by(1)
expect(subject).to have_gitlab_http_status(:redirect)
end
end
context 'when group can be created' do
it 'creates a group' do
expect { subject }.to change { Group.count }.by(1)
......
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