Commit 9d81df1d authored by Nicolas Dular's avatar Nicolas Dular

Split name to first and last name for signup

This aligns the signup with the trial signup and what
Growth::Acquisition has built as a signup experiment.
parent 1036f80c
...@@ -11,10 +11,10 @@ ...@@ -11,10 +11,10 @@
.name.form-row .name.form-row
.col.form-group .col.form-group
= f.label :first_name, _('First name'), for: 'new_user_first_name', class: 'label-bold' = f.label :first_name, _('First name'), for: 'new_user_first_name', class: 'label-bold'
= f.text_field :first_name, class: 'form-control top js-block-emoji js-validate-length', :data => { :max_length => max_first_name_length, :max_length_message => _("First Name is too long (maximum is %{max_length} characters).") % { max_length: max_first_name_length }, :qa_selector => 'new_user_firstname_field' }, required: true, title: _("This field is required.") = f.text_field :first_name, class: 'form-control top js-block-emoji js-validate-length', :data => { :max_length => max_first_name_length, :max_length_message => _("First name is too long (maximum is %{max_length} characters).") % { max_length: max_first_name_length }, :qa_selector => 'new_user_firstname_field' }, required: true, title: _("This field is required.")
.col.form-group .col.form-group
= f.label :last_name, _('Last name'), for: 'new_user_last_name', class: 'label-bold' = f.label :last_name, _('Last name'), for: 'new_user_last_name', class: 'label-bold'
= f.text_field :last_name, class: "form-control top js-block-emoji js-validate-length", :data => { :max_length => max_last_name_length, :max_length_message => _("Last Name is too long (maximum is %{max_length} characters).") % { max_length: max_last_name_length }, :qa_selector => 'new_user_lastname_field' }, required: true, title: _("This field is required.") = f.text_field :last_name, class: "form-control top js-block-emoji js-validate-length", :data => { :max_length => max_last_name_length, :max_length_message => _("Last name is too long (maximum is %{max_length} characters).") % { max_length: max_last_name_length }, :qa_selector => 'new_user_lastname_field' }, required: true, title: _("This field is required.")
.username.form-group .username.form-group
= f.label :username, class: 'label-bold' = f.label :username, class: 'label-bold'
= f.text_field :username, class: "form-control middle js-block-emoji js-validate-length js-validate-username", :data => { :min_length => min_username_length, :min_length_message => s_("SignUp|Username is too short (minimum is %{min_length} characters).") % { min_length: min_username_length }, :max_length => max_username_length, :max_length_message => _("Username is too long (maximum is %{max_length} characters).") % { max_length: max_username_length }, :qa_selector => 'new_user_username_field' }, pattern: Gitlab::PathRegex::NAMESPACE_FORMAT_REGEX_JS, required: true, title: _("Please create a username with only alphanumeric characters.") = f.text_field :username, class: "form-control middle js-block-emoji js-validate-length js-validate-username", :data => { :min_length => min_username_length, :min_length_message => s_("SignUp|Username is too short (minimum is %{min_length} characters).") % { min_length: min_username_length }, :max_length => max_username_length, :max_length_message => _("Username is too long (maximum is %{max_length} characters).") % { max_length: max_username_length }, :qa_selector => 'new_user_username_field' }, pattern: Gitlab::PathRegex::NAMESPACE_FORMAT_REGEX_JS, required: true, title: _("Please create a username with only alphanumeric characters.")
......
- max_name_length = 255 - max_first_name_length = max_last_name_length = 127
- max_username_length = 255 - max_username_length = 255
- min_username_length = 2 - min_username_length = 2
#register-pane.tab-pane.login-box{ role: 'tabpanel' } #register-pane.tab-pane.login-box{ role: 'tabpanel' }
...@@ -8,9 +8,13 @@ ...@@ -8,9 +8,13 @@
= render "devise/shared/error_messages", resource: resource = render "devise/shared/error_messages", resource: resource
- if Feature.enabled?(:invisible_captcha) - if Feature.enabled?(:invisible_captcha)
= invisible_captcha = invisible_captcha
.name.form-group .name.form-row
= f.label :name, _('Full name'), class: 'label-bold' .col.form-group
= f.text_field :name, class: "form-control top js-block-emoji js-validate-length", :data => { :max_length => max_name_length, :max_length_message => s_("SignUp|Name is too long (maximum is %{max_length} characters).") % { max_length: max_name_length }, :qa_selector => 'new_user_name_field' }, required: true, title: _("This field is required.") = f.label :first_name, _('First name'), for: 'new_user_first_name', class: 'label-bold'
= f.text_field :first_name, class: 'form-control top js-block-emoji js-validate-length', :data => { :max_length => max_first_name_length, :max_length_message => _("First name is too long (maximum is %{max_length} characters).") % { max_length: max_first_name_length }, :qa_selector => 'new_user_first_name_field' }, required: true, title: _("This field is required.")
.col.form-group
= f.label :last_name, _('Last name'), for: 'new_user_last_name', class: 'label-bold'
= f.text_field :last_name, class: "form-control top js-block-emoji js-validate-length", :data => { :max_length => max_last_name_length, :max_length_message => _("Last name is too long (maximum is %{max_length} characters).") % { max_length: max_last_name_length }, :qa_selector => 'new_user_last_name_field' }, required: true, title: _("This field is required.")
.username.form-group .username.form-group
= f.label :username, class: 'label-bold' = f.label :username, class: 'label-bold'
= f.text_field :username, class: "form-control middle js-block-emoji js-validate-length js-validate-username", :data => { :min_length => min_username_length, :min_length_message => s_("SignUp|Username is too short (minimum is %{min_length} characters).") % { min_length: min_username_length }, :max_length => max_username_length, :max_length_message => s_("SignUp|Username is too long (maximum is %{max_length} characters).") % { max_length: max_username_length }, :qa_selector => 'new_user_username_field' }, pattern: Gitlab::PathRegex::NAMESPACE_FORMAT_REGEX_JS, required: true, title: _("Please create a username with only alphanumeric characters.") = f.text_field :username, class: "form-control middle js-block-emoji js-validate-length js-validate-username", :data => { :min_length => min_username_length, :min_length_message => s_("SignUp|Username is too short (minimum is %{min_length} characters).") % { min_length: min_username_length }, :max_length => max_username_length, :max_length_message => s_("SignUp|Username is too long (maximum is %{max_length} characters).") % { max_length: max_username_length }, :qa_selector => 'new_user_username_field' }, pattern: Gitlab::PathRegex::NAMESPACE_FORMAT_REGEX_JS, required: true, title: _("Please create a username with only alphanumeric characters.")
......
---
title: Split name to first and last name for signup
merge_request: 42346
author:
type: changed
...@@ -6,8 +6,11 @@ RSpec.describe RegistrationsController do ...@@ -6,8 +6,11 @@ RSpec.describe RegistrationsController do
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
describe '#create' do describe '#create' do
let(:base_user_params) { build_stubbed(:user).slice(:first_name, :last_name, :username, :email, :password) }
let(:user_params) { { user: base_user_params } }
context 'when the user opted-in' do context 'when the user opted-in' do
let(:user_params) { { user: attributes_for(:user, email_opted_in: '1') } } let(:user_params) { { user: base_user_params.merge(email_opted_in: '1') } }
it 'sets the rest of the email_opted_in fields' do it 'sets the rest of the email_opted_in fields' do
post :create, params: user_params post :create, params: user_params
...@@ -20,7 +23,7 @@ RSpec.describe RegistrationsController do ...@@ -20,7 +23,7 @@ RSpec.describe RegistrationsController do
end end
context 'when the user opted-out' do context 'when the user opted-out' do
let(:user_params) { { user: attributes_for(:user, email_opted_in: '0') } } let(:user_params) { { user: base_user_params.merge(email_opted_in: '0') } }
it 'does not set the rest of the email_opted_in fields' do it 'does not set the rest of the email_opted_in fields' do
post :create, params: user_params post :create, params: user_params
...@@ -34,7 +37,6 @@ RSpec.describe RegistrationsController do ...@@ -34,7 +37,6 @@ RSpec.describe RegistrationsController do
context 'when reCAPTCHA experiment enabled' do context 'when reCAPTCHA experiment enabled' do
it "logs a 'User Created' message including the experiment state" do it "logs a 'User Created' message including the experiment state" do
user_params = { user: attributes_for(:user) }
allow_any_instance_of(EE::RecaptchaExperimentHelper).to receive(:show_recaptcha_sign_up?).and_return(true) allow_any_instance_of(EE::RecaptchaExperimentHelper).to receive(:show_recaptcha_sign_up?).and_return(true)
expect(Gitlab::AppLogger).to receive(:info).with(/\AUser Created: .+experiment_growth_recaptcha\?true\z/).and_call_original expect(Gitlab::AppLogger).to receive(:info).with(/\AUser Created: .+experiment_growth_recaptcha\?true\z/).and_call_original
......
...@@ -16,7 +16,8 @@ RSpec.describe 'Group or Project invitations' do ...@@ -16,7 +16,8 @@ RSpec.describe 'Group or Project invitations' do
end end
def fill_in_sign_up_form(user) def fill_in_sign_up_form(user)
fill_in 'new_user_name', with: user.name fill_in 'new_user_first_name', with: user.first_name
fill_in 'new_user_last_name', with: user.last_name
fill_in 'new_user_username', with: user.username fill_in 'new_user_username', with: user.username
fill_in 'new_user_email', with: user.email fill_in 'new_user_email', with: user.email
fill_in 'new_user_password', with: user.password fill_in 'new_user_password', with: user.password
......
...@@ -3,7 +3,15 @@ ...@@ -3,7 +3,15 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe 'Signup on EE' do RSpec.describe 'Signup on EE' do
let(:user_attrs) { attributes_for(:user) } let(:new_user) { build_stubbed(:user) }
def fill_in_signup_form
fill_in 'new_user_username', with: new_user.username
fill_in 'new_user_email', with: new_user.email
fill_in 'new_user_first_name', with: new_user.first_name
fill_in 'new_user_last_name', with: new_user.last_name
fill_in 'new_user_password', with: new_user.password
end
context 'for Gitlab.com' do context 'for Gitlab.com' do
before do before do
...@@ -14,14 +22,11 @@ RSpec.describe 'Signup on EE' do ...@@ -14,14 +22,11 @@ RSpec.describe 'Signup on EE' do
it 'creates the user and sets the email_opted_in field truthy' do it 'creates the user and sets the email_opted_in field truthy' do
visit root_path visit root_path
fill_in 'new_user_name', with: user_attrs[:name] fill_in_signup_form
fill_in 'new_user_username', with: user_attrs[:username] check 'new_user_email_opted_in'
fill_in 'new_user_email', with: user_attrs[:email]
fill_in 'new_user_password', with: user_attrs[:password]
check 'new_user_email_opted_in'
click_button "Register" click_button "Register"
user = User.find_by_username!(user_attrs[:username]) user = User.find_by_username!(new_user[:username])
expect(user.email_opted_in).to be_truthy expect(user.email_opted_in).to be_truthy
expect(user.email_opted_in_ip).to be_present expect(user.email_opted_in_ip).to be_present
expect(user.email_opted_in_source).to eq('GitLab.com') expect(user.email_opted_in_source).to eq('GitLab.com')
...@@ -33,13 +38,10 @@ RSpec.describe 'Signup on EE' do ...@@ -33,13 +38,10 @@ RSpec.describe 'Signup on EE' do
it 'creates the user and sets the email_opted_in field falsey' do it 'creates the user and sets the email_opted_in field falsey' do
visit root_path visit root_path
fill_in 'new_user_name', with: user_attrs[:name] fill_in_signup_form
fill_in 'new_user_username', with: user_attrs[:username]
fill_in 'new_user_email', with: user_attrs[:email]
fill_in 'new_user_password', with: user_attrs[:password]
click_button "Register" click_button "Register"
user = User.find_by_username!(user_attrs[:username]) user = User.find_by_username!(new_user[:username])
expect(user.email_opted_in).to be_falsey expect(user.email_opted_in).to be_falsey
expect(user.email_opted_in_ip).to be_blank expect(user.email_opted_in_ip).to be_blank
expect(user.email_opted_in_source).to be_blank expect(user.email_opted_in_source).to be_blank
...@@ -50,10 +52,7 @@ RSpec.describe 'Signup on EE' do ...@@ -50,10 +52,7 @@ RSpec.describe 'Signup on EE' do
it 'redirects to step 2 of the signup process, sets the role and setup for company and redirects back' do it 'redirects to step 2 of the signup process, sets the role and setup for company and redirects back' do
visit new_user_registration_path visit new_user_registration_path
fill_in 'new_user_name', with: user_attrs[:name].split(' ').first fill_in_signup_form
fill_in 'new_user_username', with: user_attrs[:username]
fill_in 'new_user_email', with: user_attrs[:email]
fill_in 'new_user_password', with: user_attrs[:password]
click_button 'Register' click_button 'Register'
visit new_project_path visit new_project_path
...@@ -62,7 +61,7 @@ RSpec.describe 'Signup on EE' do ...@@ -62,7 +61,7 @@ RSpec.describe 'Signup on EE' do
select 'Software Developer', from: 'user_role' select 'Software Developer', from: 'user_role'
choose 'user_setup_for_company_true' choose 'user_setup_for_company_true'
click_button 'Get started!' click_button 'Get started!'
user = User.find_by_username(user_attrs[:username]) user = User.find_by_username(new_user[:username])
expect(user.software_developer_role?).to be_truthy expect(user.software_developer_role?).to be_truthy
expect(user.setup_for_company).to be_truthy expect(user.setup_for_company).to be_truthy
...@@ -80,13 +79,10 @@ RSpec.describe 'Signup on EE' do ...@@ -80,13 +79,10 @@ RSpec.describe 'Signup on EE' do
expect(page).not_to have_selector("[name='new_user_email_opted_in']") expect(page).not_to have_selector("[name='new_user_email_opted_in']")
fill_in 'new_user_name', with: user_attrs[:name] fill_in_signup_form
fill_in 'new_user_username', with: user_attrs[:username]
fill_in 'new_user_email', with: user_attrs[:email]
fill_in 'new_user_password', with: user_attrs[:password]
click_button "Register" click_button "Register"
user = User.find_by_username!(user_attrs[:username]) user = User.find_by_username!(new_user[:username])
expect(user.email_opted_in).to be_falsey expect(user.email_opted_in).to be_falsey
expect(user.email_opted_in_ip).to be_blank expect(user.email_opted_in_ip).to be_blank
expect(user.email_opted_in_source).to be_blank expect(user.email_opted_in_source).to be_blank
......
...@@ -11329,9 +11329,6 @@ msgstr "" ...@@ -11329,9 +11329,6 @@ msgstr ""
msgid "Finished" msgid "Finished"
msgstr "" msgstr ""
msgid "First Name is too long (maximum is %{max_length} characters)."
msgstr ""
msgid "First Seen" msgid "First Seen"
msgstr "" msgstr ""
...@@ -11341,6 +11338,9 @@ msgstr "" ...@@ -11341,6 +11338,9 @@ msgstr ""
msgid "First name" msgid "First name"
msgstr "" msgstr ""
msgid "First name is too long (maximum is %{max_length} characters)."
msgstr ""
msgid "First seen" msgid "First seen"
msgstr "" msgstr ""
...@@ -14821,9 +14821,6 @@ msgstr "" ...@@ -14821,9 +14821,6 @@ msgstr ""
msgid "Last Accessed On" msgid "Last Accessed On"
msgstr "" msgstr ""
msgid "Last Name is too long (maximum is %{max_length} characters)."
msgstr ""
msgid "Last Pipeline" msgid "Last Pipeline"
msgstr "" msgstr ""
...@@ -14857,6 +14854,9 @@ msgstr "" ...@@ -14857,6 +14854,9 @@ msgstr ""
msgid "Last name" msgid "Last name"
msgstr "" msgstr ""
msgid "Last name is too long (maximum is %{max_length} characters)."
msgstr ""
msgid "Last reply by" msgid "Last reply by"
msgstr "" msgstr ""
...@@ -23808,9 +23808,6 @@ msgstr "" ...@@ -23808,9 +23808,6 @@ msgstr ""
msgid "SignUp|Last Name is too long (maximum is %{max_length} characters)." msgid "SignUp|Last Name is too long (maximum is %{max_length} characters)."
msgstr "" msgstr ""
msgid "SignUp|Name is too long (maximum is %{max_length} characters)."
msgstr ""
msgid "SignUp|Username is too long (maximum is %{max_length} characters)." msgid "SignUp|Username is too long (maximum is %{max_length} characters)."
msgstr "" msgstr ""
......
...@@ -5,7 +5,8 @@ module QA ...@@ -5,7 +5,8 @@ module QA
module Main module Main
class SignUp < Page::Base class SignUp < Page::Base
view 'app/views/devise/shared/_signup_box.html.haml' do view 'app/views/devise/shared/_signup_box.html.haml' do
element :new_user_name_field element :new_user_first_name_field
element :new_user_last_name_field
element :new_user_username_field element :new_user_username_field
element :new_user_email_field element :new_user_email_field
element :new_user_password_field element :new_user_password_field
...@@ -18,7 +19,8 @@ module QA ...@@ -18,7 +19,8 @@ module QA
end end
def sign_up!(user) def sign_up!(user)
fill_element :new_user_name_field, user.name fill_element :new_user_first_name_field, user.first_name
fill_element :new_user_last_name_field, user.last_name
fill_element :new_user_username_field, user.username fill_element :new_user_username_field, user.username
fill_element :new_user_email_field, user.email fill_element :new_user_email_field, user.email
fill_element :new_user_password_field, user.password fill_element :new_user_password_field, user.password
......
...@@ -11,6 +11,8 @@ module QA ...@@ -11,6 +11,8 @@ module QA
attribute :id attribute :id
attribute :name attribute :name
attribute :first_name
attribute :last_name
attribute :email attribute :email
def initialize def initialize
...@@ -34,6 +36,14 @@ module QA ...@@ -34,6 +36,14 @@ module QA
@name ||= api_resource&.dig(:name) || "QA User #{unique_id}" @name ||= api_resource&.dig(:name) || "QA User #{unique_id}"
end end
def first_name
name.split(' ').first
end
def last_name
name.split(' ').drop(1).join(' ')
end
def email def email
@email ||= begin @email ||= begin
api_email = api_resource&.dig(:email) api_email = api_resource&.dig(:email)
......
...@@ -80,7 +80,7 @@ RSpec.describe RegistrationsController do ...@@ -80,7 +80,7 @@ RSpec.describe RegistrationsController do
end end
describe '#create' do describe '#create' do
let(:base_user_params) { { name: 'new_user', username: 'new_username', email: 'new@user.com', password: 'Any_password' } } let(:base_user_params) { { first_name: 'first', last_name: 'last', username: 'new_username', email: 'new@user.com', password: 'Any_password' } }
let(:user_params) { { user: base_user_params } } let(:user_params) { { user: base_user_params } }
context 'email confirmation' do context 'email confirmation' do
...@@ -370,21 +370,12 @@ RSpec.describe RegistrationsController do ...@@ -370,21 +370,12 @@ RSpec.describe RegistrationsController do
expect(subject.current_user).not_to be_nil expect(subject.current_user).not_to be_nil
end end
context 'with the experimental signup flow enabled and the user is part of the experimental group' do it 'sets name from first and last name' do
before do post :create, params: { new_user: base_user_params }
stub_experiment(signup_flow: true)
stub_experiment_for_user(signup_flow: true)
end
let(:base_user_params) { { first_name: 'First', last_name: 'Last', username: 'new_username', email: 'new@user.com', password: 'Any_password' } }
it 'sets name from first and last name' do expect(User.last.first_name).to eq(base_user_params[:first_name])
post :create, params: { new_user: base_user_params } expect(User.last.last_name).to eq(base_user_params[:last_name])
expect(User.last.name).to eq("#{base_user_params[:first_name]} #{base_user_params[:last_name]}")
expect(User.last.first_name).to eq(base_user_params[:first_name])
expect(User.last.last_name).to eq(base_user_params[:last_name])
expect(User.last.name).to eq("#{base_user_params[:first_name]} #{base_user_params[:last_name]}")
end
end end
end end
......
...@@ -23,7 +23,8 @@ RSpec.describe 'Group or Project invitations', :aggregate_failures do ...@@ -23,7 +23,8 @@ RSpec.describe 'Group or Project invitations', :aggregate_failures do
end end
def fill_in_sign_up_form(new_user) def fill_in_sign_up_form(new_user)
fill_in 'new_user_name', with: new_user.name fill_in 'new_user_first_name', with: new_user.first_name
fill_in 'new_user_last_name', with: new_user.last_name
fill_in 'new_user_username', with: new_user.username fill_in 'new_user_username', with: new_user.username
fill_in 'new_user_email', with: new_user.email fill_in 'new_user_email', with: new_user.email
fill_in 'new_user_password', with: new_user.password fill_in 'new_user_password', with: new_user.password
......
...@@ -7,6 +7,14 @@ RSpec.shared_examples 'Signup' do ...@@ -7,6 +7,14 @@ RSpec.shared_examples 'Signup' do
let(:new_user) { build_stubbed(:user) } let(:new_user) { build_stubbed(:user) }
def fill_in_signup_form
fill_in 'new_user_username', with: new_user.username
fill_in 'new_user_email', with: new_user.email
fill_in 'new_user_first_name', with: new_user.first_name
fill_in 'new_user_last_name', with: new_user.last_name
fill_in 'new_user_password', with: new_user.password
end
describe 'username validation', :js do describe 'username validation', :js do
before do before do
visit new_user_registration_path visit new_user_registration_path
...@@ -144,20 +152,9 @@ RSpec.shared_examples 'Signup' do ...@@ -144,20 +152,9 @@ RSpec.shared_examples 'Signup' do
it 'creates the user account and sends a confirmation email' do it 'creates the user account and sends a confirmation email' do
visit new_user_registration_path visit new_user_registration_path
fill_in 'new_user_username', with: new_user.username fill_in_signup_form
fill_in 'new_user_email', with: new_user.email
if Gitlab::Experimentation.enabled?(:signup_flow)
fill_in 'new_user_first_name', with: new_user.first_name
fill_in 'new_user_last_name', with: new_user.last_name
else
fill_in 'new_user_name', with: new_user.name
end
fill_in 'new_user_password', with: new_user.password
expect { click_button 'Register' }.to change { User.count }.by(1) expect { click_button 'Register' }.to change { User.count }.by(1)
expect(current_path).to eq users_almost_there_path expect(current_path).to eq users_almost_there_path
expect(page).to have_content('Please check your email to confirm your account') expect(page).to have_content('Please check your email to confirm your account')
end end
...@@ -171,46 +168,14 @@ RSpec.shared_examples 'Signup' do ...@@ -171,46 +168,14 @@ RSpec.shared_examples 'Signup' do
it 'creates the user account and sends a confirmation email' do it 'creates the user account and sends a confirmation email' do
visit new_user_registration_path visit new_user_registration_path
fill_in 'new_user_username', with: new_user.username fill_in_signup_form
fill_in 'new_user_email', with: new_user.email
if Gitlab::Experimentation.enabled?(:signup_flow)
fill_in 'new_user_first_name', with: new_user.first_name
fill_in 'new_user_last_name', with: new_user.last_name
else
fill_in 'new_user_name', with: new_user.name
end
fill_in 'new_user_password', with: new_user.password
expect { click_button 'Register' }.to change { User.count }.by(1) expect { click_button 'Register' }.to change { User.count }.by(1)
expect(current_path).to eq users_sign_up_welcome_path expect(current_path).to eq users_sign_up_welcome_path
end end
end end
end end
context "when sigining up with different cased emails" do
it "creates the user successfully" do
visit new_user_registration_path
fill_in 'new_user_username', with: new_user.username
fill_in 'new_user_email', with: new_user.email
if Gitlab::Experimentation.enabled?(:signup_flow)
fill_in 'new_user_first_name', with: new_user.first_name
fill_in 'new_user_last_name', with: new_user.last_name
else
fill_in 'new_user_name', with: new_user.name
end
fill_in 'new_user_password', with: new_user.password
click_button "Register"
expect(current_path).to eq users_sign_up_welcome_path
end
end
context "when not sending confirmation email" do context "when not sending confirmation email" do
before do before do
stub_application_setting(send_user_confirmation_email: false) stub_application_setting(send_user_confirmation_email: false)
...@@ -219,17 +184,7 @@ RSpec.shared_examples 'Signup' do ...@@ -219,17 +184,7 @@ RSpec.shared_examples 'Signup' do
it 'creates the user account and goes to dashboard' do it 'creates the user account and goes to dashboard' do
visit new_user_registration_path visit new_user_registration_path
fill_in 'new_user_username', with: new_user.username fill_in_signup_form
fill_in 'new_user_email', with: new_user.email
if Gitlab::Experimentation.enabled?(:signup_flow)
fill_in 'new_user_first_name', with: new_user.first_name
fill_in 'new_user_last_name', with: new_user.last_name
else
fill_in 'new_user_name', with: new_user.name
end
fill_in 'new_user_password', with: new_user.password
click_button "Register" click_button "Register"
expect(current_path).to eq users_sign_up_welcome_path expect(current_path).to eq users_sign_up_welcome_path
...@@ -239,20 +194,10 @@ RSpec.shared_examples 'Signup' do ...@@ -239,20 +194,10 @@ RSpec.shared_examples 'Signup' do
context 'with errors' do context 'with errors' do
it "displays the errors" do it "displays the errors" do
existing_user = create(:user) create(:user, email: new_user.email)
visit new_user_registration_path visit new_user_registration_path
if Gitlab::Experimentation.enabled?(:signup_flow) fill_in_signup_form
fill_in 'new_user_first_name', with: new_user.first_name
fill_in 'new_user_last_name', with: new_user.last_name
else
fill_in 'new_user_name', with: new_user.name
end
fill_in 'new_user_username', with: new_user.username
fill_in 'new_user_email', with: existing_user.email
fill_in 'new_user_password', with: new_user.password
click_button "Register" click_button "Register"
expect(current_path).to eq user_registration_path expect(current_path).to eq user_registration_path
...@@ -261,20 +206,10 @@ RSpec.shared_examples 'Signup' do ...@@ -261,20 +206,10 @@ RSpec.shared_examples 'Signup' do
end end
it 'does not redisplay the password' do it 'does not redisplay the password' do
existing_user = create(:user) create(:user, email: new_user.email)
visit new_user_registration_path visit new_user_registration_path
if Gitlab::Experimentation.enabled?(:signup_flow) fill_in_signup_form
fill_in 'new_user_first_name', with: new_user.first_name
fill_in 'new_user_last_name', with: new_user.last_name
else
fill_in 'new_user_name', with: new_user.name
end
fill_in 'new_user_username', with: new_user.username
fill_in 'new_user_email', with: existing_user.email
fill_in 'new_user_password', with: new_user.password
click_button "Register" click_button "Register"
expect(current_path).to eq user_registration_path expect(current_path).to eq user_registration_path
...@@ -290,18 +225,7 @@ RSpec.shared_examples 'Signup' do ...@@ -290,18 +225,7 @@ RSpec.shared_examples 'Signup' do
it 'requires the user to check the checkbox' do it 'requires the user to check the checkbox' do
visit new_user_registration_path visit new_user_registration_path
fill_in 'new_user_username', with: new_user.username fill_in_signup_form
fill_in 'new_user_email', with: new_user.email
if Gitlab::Experimentation.enabled?(:signup_flow)
fill_in 'new_user_first_name', with: new_user.first_name
fill_in 'new_user_last_name', with: new_user.last_name
else
fill_in 'new_user_name', with: new_user.name
end
fill_in 'new_user_password', with: new_user.password
click_button 'Register' click_button 'Register'
expect(current_path).to eq new_user_session_path expect(current_path).to eq new_user_session_path
...@@ -311,19 +235,8 @@ RSpec.shared_examples 'Signup' do ...@@ -311,19 +235,8 @@ RSpec.shared_examples 'Signup' do
it 'asks the user to accept terms before going to the dashboard' do it 'asks the user to accept terms before going to the dashboard' do
visit new_user_registration_path visit new_user_registration_path
fill_in 'new_user_username', with: new_user.username fill_in_signup_form
fill_in 'new_user_email', with: new_user.email
if Gitlab::Experimentation.enabled?(:signup_flow)
fill_in 'new_user_first_name', with: new_user.first_name
fill_in 'new_user_last_name', with: new_user.last_name
else
fill_in 'new_user_name', with: new_user.name
end
fill_in 'new_user_password', with: new_user.password
check :terms_opt_in check :terms_opt_in
click_button "Register" click_button "Register"
expect(current_path).to eq users_sign_up_welcome_path expect(current_path).to eq users_sign_up_welcome_path
...@@ -353,17 +266,7 @@ RSpec.shared_examples 'Signup' do ...@@ -353,17 +266,7 @@ RSpec.shared_examples 'Signup' do
it 'prevents from signing up' do it 'prevents from signing up' do
visit new_user_registration_path visit new_user_registration_path
fill_in 'new_user_username', with: new_user.username fill_in_signup_form
fill_in 'new_user_email', with: new_user.email
if Gitlab::Experimentation.enabled?(:signup_flow)
fill_in 'new_user_first_name', with: new_user.first_name
fill_in 'new_user_last_name', with: new_user.last_name
else
fill_in 'new_user_name', with: new_user.name
end
fill_in 'new_user_password', with: new_user.password
expect { click_button 'Register' }.not_to change { User.count } expect { click_button 'Register' }.not_to change { User.count }
expect(page).to have_content('There was an error with the reCAPTCHA. Please solve the reCAPTCHA again.') expect(page).to have_content('There was an error with the reCAPTCHA. Please solve the reCAPTCHA again.')
...@@ -374,17 +277,7 @@ RSpec.shared_examples 'Signup' do ...@@ -374,17 +277,7 @@ RSpec.shared_examples 'Signup' do
it 'prevents from signing up' do it 'prevents from signing up' do
visit new_user_registration_path visit new_user_registration_path
fill_in 'new_user_username', with: new_user.username fill_in_signup_form
fill_in 'new_user_email', with: new_user.email
if Gitlab::Experimentation.enabled?(:signup_flow)
fill_in 'new_user_first_name', with: new_user.first_name
fill_in 'new_user_last_name', with: new_user.last_name
else
fill_in 'new_user_name', with: new_user.name
end
fill_in 'new_user_password', with: new_user.password
expect { click_button 'Register' }.not_to change { User.count } expect { click_button 'Register' }.not_to change { User.count }
expect(page).to have_content('That was a bit too quick! Please resubmit.') expect(page).to have_content('That was a bit too quick! Please resubmit.')
...@@ -393,36 +286,27 @@ RSpec.shared_examples 'Signup' do ...@@ -393,36 +286,27 @@ RSpec.shared_examples 'Signup' do
end end
it 'redirects to step 2 of the signup process, sets the role and redirects back' do it 'redirects to step 2 of the signup process, sets the role and redirects back' do
new_user = build_stubbed(:user)
visit new_user_registration_path visit new_user_registration_path
fill_in 'new_user_username', with: new_user.username fill_in_signup_form
fill_in 'new_user_email', with: new_user.email
if Gitlab::Experimentation.enabled?(:signup_flow)
fill_in 'new_user_first_name', with: new_user.first_name
fill_in 'new_user_last_name', with: new_user.last_name
else
fill_in 'new_user_name', with: new_user.name
end
fill_in 'new_user_password', with: new_user.password
click_button 'Register' click_button 'Register'
visit new_project_path visit new_project_path
expect(page).to have_current_path(users_sign_up_welcome_path) expect(page).to have_current_path(users_sign_up_welcome_path)
select 'Software Developer', from: 'user_role' select 'Software Developer', from: 'user_role'
click_button 'Get started!' click_button 'Get started!'
new_user = User.find_by_username(new_user.username)
expect(new_user.software_developer_role?).to be_truthy created_user = User.find_by_username(new_user.username)
expect(new_user.setup_for_company).to be_nil
expect(created_user.software_developer_role?).to be_truthy
expect(created_user.setup_for_company).to be_nil
expect(page).to have_current_path(new_project_path) expect(page).to have_current_path(new_project_path)
end end
end end
RSpec.shared_examples 'Signup name validation' do |field, max_length| RSpec.shared_examples 'Signup name validation' do |field, max_length, label|
before do before do
visit new_user_registration_path visit new_user_registration_path
end end
...@@ -446,10 +330,10 @@ RSpec.shared_examples 'Signup name validation' do |field, max_length| ...@@ -446,10 +330,10 @@ RSpec.shared_examples 'Signup name validation' do |field, max_length|
expect(find('.name')).to have_css '.gl-field-error-outline' expect(find('.name')).to have_css '.gl-field-error-outline'
end end
it "shows an error message if the user\'s fullname is longer than #{max_length} characters" do it "shows an error message if the user\'s #{label} is longer than #{max_length} characters" do
fill_in field, with: 'n' * (max_length + 1) fill_in field, with: 'n' * (max_length + 1)
expect(page).to have_content("Name is too long (maximum is #{max_length} characters).") expect(page).to have_content("#{label} is too long (maximum is #{max_length} characters).")
end end
it 'shows an error message if the username contains emojis' do it 'shows an error message if the username contains emojis' do
...@@ -467,7 +351,8 @@ RSpec.describe 'With original flow' do ...@@ -467,7 +351,8 @@ RSpec.describe 'With original flow' do
end end
it_behaves_like 'Signup' it_behaves_like 'Signup'
it_behaves_like 'Signup name validation', 'new_user_name', 255 it_behaves_like 'Signup name validation', 'new_user_first_name', 127, 'First name'
it_behaves_like 'Signup name validation', 'new_user_last_name', 127, 'Last name'
end end
RSpec.describe 'With experimental flow' do RSpec.describe 'With experimental flow' do
...@@ -477,8 +362,8 @@ RSpec.describe 'With experimental flow' do ...@@ -477,8 +362,8 @@ RSpec.describe 'With experimental flow' do
end end
it_behaves_like 'Signup' it_behaves_like 'Signup'
it_behaves_like 'Signup name validation', 'new_user_first_name', 127 it_behaves_like 'Signup name validation', 'new_user_first_name', 127, 'First name'
it_behaves_like 'Signup name validation', 'new_user_last_name', 127 it_behaves_like 'Signup name validation', 'new_user_last_name', 127, 'Last name'
context 'when terms_opt_in experimental is enabled' do context 'when terms_opt_in experimental is enabled' do
include TermsHelper include TermsHelper
......
...@@ -4,11 +4,11 @@ require 'spec_helper' ...@@ -4,11 +4,11 @@ require 'spec_helper'
RSpec.describe Users::BuildService do RSpec.describe Users::BuildService do
describe '#execute' do describe '#execute' do
let(:params) do let(:params) { build_stubbed(:user).slice(:first_name, :last_name, :username, :email, :password) }
{ name: 'John Doe', username: 'jduser', email: 'jd@example.com', password: 'mydummypass' }
end
context 'with an admin user' do context 'with an admin user' do
let(:params) { build_stubbed(:user).slice(:name, :username, :email, :password) }
let(:admin_user) { create(:admin) } let(:admin_user) { create(:admin) }
let(:service) { described_class.new(admin_user, ActionController::Parameters.new(params).permit!) } let(:service) { described_class.new(admin_user, ActionController::Parameters.new(params).permit!) }
......
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