Commit 6bf44358 authored by Etienne Baqué's avatar Etienne Baqué

Merge branch 'jswain_jobs_to_be_done_persisted' into 'master'

Persist jobs_to_be_done answers to DB

See merge request gitlab-org/gitlab!70638
parents 02f8eadd 203a58cf
......@@ -318,6 +318,7 @@ class User < ApplicationRecord
delegate :webauthn_xid, :webauthn_xid=, to: :user_detail, allow_nil: true
delegate :pronouns, :pronouns=, to: :user_detail, allow_nil: true
delegate :pronunciation, :pronunciation=, to: :user_detail, allow_nil: true
delegate :registration_objective, :registration_objective=, to: :user_detail, allow_nil: true
accepts_nested_attributes_for :user_preference, update_only: true
accepts_nested_attributes_for :user_detail, update_only: true
......
......@@ -3,8 +3,11 @@
class UserDetail < ApplicationRecord
extend ::Gitlab::Utils::Override
include IgnorableColumns
ignore_columns %i[bio_html cached_markdown_version], remove_with: '13.6', remove_after: '2021-10-22'
REGISTRATION_OBJECTIVE_PAIRS = { basics: 0, move_repository: 1, code_storage: 2, exploring: 3, ci: 4, other: 5, joining_team: 6 }.freeze
belongs_to :user
validates :pronouns, length: { maximum: 50 }
......@@ -14,6 +17,8 @@ class UserDetail < ApplicationRecord
before_save :prevent_nil_bio
enum registration_objective: REGISTRATION_OBJECTIVE_PAIRS, _suffix: true
private
def prevent_nil_bio
......
# frozen_string_literal: true
class AddRegistrationObjectiveToUserDetail < Gitlab::Database::Migration[1.0]
def change
add_column :user_details, :registration_objective, :smallint
end
end
9204c844b22ad0d3a938ed908377c8baacdda038725a5cf105e4b11841c1ae21
\ No newline at end of file
......@@ -19764,6 +19764,7 @@ CREATE TABLE user_details (
provisioned_by_group_id bigint,
pronouns text,
pronunciation text,
registration_objective smallint,
CONSTRAINT check_245664af82 CHECK ((char_length(webauthn_xid) <= 100)),
CONSTRAINT check_b132136b01 CHECK ((char_length(other_role) <= 100)),
CONSTRAINT check_eeeaf8d4f0 CHECK ((char_length(pronouns) <= 50)),
......@@ -4,7 +4,7 @@ import Tracking from '~/tracking';
const select = document.querySelector('.js-jobs-to-be-done-dropdown');
if (select) {
Tracking.enableFormTracking(
{ fields: { allow: ['jobs_to_be_done', 'jobs_to_be_done_other'] } },
{ fields: { allow: ['jobs_to_be_done_other'] } },
getExperimentContexts('jobs_to_be_done'),
);
......
......@@ -44,7 +44,7 @@ module EE
override :update_params
def update_params
clean_params = super.merge(params.require(:user).permit(:email_opted_in))
clean_params = super.merge(params.require(:user).permit(:email_opted_in, :registration_objective))
return clean_params unless ::Gitlab.dev_env_or_com?
......
......@@ -10,8 +10,10 @@ module EE
super.merge(api_path: suggestion_path)
end
def shuffled_jobs_to_be_done_options
jobs_to_be_done_options.shuffle.append([_('A different reason'), 'other'])
def shuffled_registration_objective_options
options = registration_objective_options
other = options.extract!(:other).to_a.flatten
options.to_a.shuffle.append(other).map { |option| option.reverse }
end
private
......@@ -23,15 +25,10 @@ module EE
end
end
def jobs_to_be_done_options
[
_('I want to learn the basics of Git'),
_('I want to move my repository to GitLab from somewhere else'),
_('I want to store my code'),
_('I want to explore GitLab to see if it’s worth switching to'),
_('I want to use GitLab CI with my existing repository'),
_('I’m joining my team who’s already on GitLab')
]
def registration_objective_options
localized_jobs_to_be_done_choices.merge(
joining_team: _('I’m joining my team who’s already on GitLab')
)
end
end
end
......@@ -2,10 +2,8 @@
- e.try do
.row
.form-group.col-sm-12
= label_tag :jobs_to_be_done, _("I'm signing up for GitLab because:")
= select_tag :jobs_to_be_done,
options_for_select(shuffled_jobs_to_be_done_options),
include_blank: _('Please select...'), class: 'form-control js-jobs-to-be-done-dropdown'
= label_tag :user_registration_objective, _("I'm signing up for GitLab because:")
= f.select :registration_objective, shuffled_registration_objective_options, { include_blank: _('Please select...') }, class: 'form-control js-jobs-to-be-done-dropdown'
.row
.form-group.col-sm-12.js-jobs-to-be-done-other-group.hidden
= label_tag :jobs_to_be_done_other, _('Why are you signing up? (Optional)')
......
......@@ -135,7 +135,8 @@ RSpec.describe Registrations::WelcomeController do
user: {
role: 'software_developer',
setup_for_company: setup_for_company,
email_opted_in: email_opted_in
email_opted_in: email_opted_in,
registration_objective: 'code_storage'
}
}
end
......@@ -179,6 +180,14 @@ RSpec.describe Registrations::WelcomeController do
allow(::Gitlab).to receive(:com?).and_return(true)
end
context 'when registration_objective field is provided' do
it 'sets the registration_objective' do
subject
expect(controller.current_user.registration_objective).to eq('code_storage')
end
end
context 'when setup for company is false' do
context 'when the user opted in' do
let(:email_opted_in) { '1' }
......
......@@ -59,7 +59,7 @@ RSpec.describe 'Welcome screen', :js do
it 'allows specifying other for the jobs_to_be_done experiment', :experiment do
expect(page).not_to have_content('Why are you signing up? (Optional)')
select 'A different reason', from: 'jobs_to_be_done'
select 'A different reason', from: 'user_registration_objective'
expect(page).to have_content('Why are you signing up? (Optional)')
......
......@@ -9,25 +9,17 @@ RSpec.describe EE::RegistrationsHelper do
end
end
describe '#shuffled_jobs_to_be_done_options' do
subject { helper.shuffled_jobs_to_be_done_options }
describe '#shuffled_registration_objective_options' do
subject(:shuffled_options) { helper.shuffled_registration_objective_options }
let(:array_double) { double(:array) }
it 'has values that match all UserDetail registration objective keys' do
shuffled_option_values = shuffled_options.map { |item| item.last }
it 'uses shuffle' do
allow(helper).to receive(:jobs_to_be_done_options).and_return(array_double)
expect(array_double).to receive(:shuffle).and_return([])
subject
end
it 'has a number of options' do
expect(subject.count).to eq(7)
expect(shuffled_option_values).to contain_exactly(*UserDetail.registration_objectives.keys)
end
it '"other" is always the last option' do
expect(subject.last).to eq(['A different reason', 'other'])
expect(shuffled_options.last).to eq(['A different reason', 'other'])
end
end
end
......@@ -66,7 +66,7 @@ RSpec.describe 'registrations/welcome/show' do
let_it_be(:stubbed_experiments) { { jobs_to_be_done: :candidate } }
it 'renders a select and text field for additional information' do
is_expected.to have_selector('select[name="jobs_to_be_done"]')
is_expected.to have_selector('select[name="user[registration_objective]"]')
is_expected.to have_selector('input[name="jobs_to_be_done_other"]', visible: false)
end
end
......
......@@ -11,6 +11,8 @@ RSpec.describe NamespaceSetting, type: :model do
it { is_expected.to belong_to(:namespace) }
end
it { is_expected.to define_enum_for(:jobs_to_be_done).with_values([:basics, :move_repository, :code_storage, :exploring, :ci, :other]).with_suffix }
describe "validations" do
describe "#default_branch_name_content" do
let_it_be(:group) { create(:group) }
......
......@@ -4,6 +4,7 @@ require 'spec_helper'
RSpec.describe UserDetail do
it { is_expected.to belong_to(:user) }
it { is_expected.to define_enum_for(:registration_objective).with_values([:basics, :move_repository, :code_storage, :exploring, :ci, :other, :joining_team]).with_suffix }
describe 'validations' do
describe '#job_title' do
......
......@@ -79,6 +79,9 @@ RSpec.describe User do
it { is_expected.to delegate_method(:bio).to(:user_detail).allow_nil }
it { is_expected.to delegate_method(:bio=).to(:user_detail).with_arguments(:args).allow_nil }
it { is_expected.to delegate_method(:registration_objective).to(:user_detail).allow_nil }
it { is_expected.to delegate_method(:registration_objective=).to(:user_detail).with_arguments(:args).allow_nil }
end
describe 'associations' do
......
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