Commit 203a58cf authored by Jay's avatar Jay Committed by Etienne Baqué

Persist jobs_to_be_done answers to DB

parent a0ddad33
...@@ -318,6 +318,7 @@ class User < ApplicationRecord ...@@ -318,6 +318,7 @@ class User < ApplicationRecord
delegate :webauthn_xid, :webauthn_xid=, to: :user_detail, allow_nil: true delegate :webauthn_xid, :webauthn_xid=, to: :user_detail, allow_nil: true
delegate :pronouns, :pronouns=, 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 :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_preference, update_only: true
accepts_nested_attributes_for :user_detail, update_only: true accepts_nested_attributes_for :user_detail, update_only: true
......
...@@ -3,8 +3,11 @@ ...@@ -3,8 +3,11 @@
class UserDetail < ApplicationRecord class UserDetail < ApplicationRecord
extend ::Gitlab::Utils::Override extend ::Gitlab::Utils::Override
include IgnorableColumns include IgnorableColumns
ignore_columns %i[bio_html cached_markdown_version], remove_with: '13.6', remove_after: '2021-10-22' 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 belongs_to :user
validates :pronouns, length: { maximum: 50 } validates :pronouns, length: { maximum: 50 }
...@@ -14,6 +17,8 @@ class UserDetail < ApplicationRecord ...@@ -14,6 +17,8 @@ class UserDetail < ApplicationRecord
before_save :prevent_nil_bio before_save :prevent_nil_bio
enum registration_objective: REGISTRATION_OBJECTIVE_PAIRS, _suffix: true
private private
def prevent_nil_bio 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
...@@ -19762,6 +19762,7 @@ CREATE TABLE user_details ( ...@@ -19762,6 +19762,7 @@ CREATE TABLE user_details (
provisioned_by_group_id bigint, provisioned_by_group_id bigint,
pronouns text, pronouns text,
pronunciation text, pronunciation text,
registration_objective smallint,
CONSTRAINT check_245664af82 CHECK ((char_length(webauthn_xid) <= 100)), CONSTRAINT check_245664af82 CHECK ((char_length(webauthn_xid) <= 100)),
CONSTRAINT check_b132136b01 CHECK ((char_length(other_role) <= 100)), CONSTRAINT check_b132136b01 CHECK ((char_length(other_role) <= 100)),
CONSTRAINT check_eeeaf8d4f0 CHECK ((char_length(pronouns) <= 50)), CONSTRAINT check_eeeaf8d4f0 CHECK ((char_length(pronouns) <= 50)),
...@@ -4,7 +4,7 @@ import Tracking from '~/tracking'; ...@@ -4,7 +4,7 @@ import Tracking from '~/tracking';
const select = document.querySelector('.js-jobs-to-be-done-dropdown'); const select = document.querySelector('.js-jobs-to-be-done-dropdown');
if (select) { if (select) {
Tracking.enableFormTracking( 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'), getExperimentContexts('jobs_to_be_done'),
); );
......
...@@ -44,7 +44,7 @@ module EE ...@@ -44,7 +44,7 @@ module EE
override :update_params override :update_params
def 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? return clean_params unless ::Gitlab.dev_env_or_com?
......
...@@ -10,8 +10,10 @@ module EE ...@@ -10,8 +10,10 @@ module EE
super.merge(api_path: suggestion_path) super.merge(api_path: suggestion_path)
end end
def shuffled_jobs_to_be_done_options def shuffled_registration_objective_options
jobs_to_be_done_options.shuffle.append([_('A different reason'), 'other']) options = registration_objective_options
other = options.extract!(:other).to_a.flatten
options.to_a.shuffle.append(other).map { |option| option.reverse }
end end
private private
...@@ -23,15 +25,10 @@ module EE ...@@ -23,15 +25,10 @@ module EE
end end
end end
def jobs_to_be_done_options def registration_objective_options
[ localized_jobs_to_be_done_choices.merge(
_('I want to learn the basics of Git'), joining_team: _('I’m joining my team who’s already on GitLab')
_('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')
]
end end
end end
end end
...@@ -2,10 +2,8 @@ ...@@ -2,10 +2,8 @@
- e.try do - e.try do
.row .row
.form-group.col-sm-12 .form-group.col-sm-12
= label_tag :jobs_to_be_done, _("I'm signing up for GitLab because:") = label_tag :user_registration_objective, _("I'm signing up for GitLab because:")
= select_tag :jobs_to_be_done, = f.select :registration_objective, shuffled_registration_objective_options, { include_blank: _('Please select...') }, class: 'form-control js-jobs-to-be-done-dropdown'
options_for_select(shuffled_jobs_to_be_done_options),
include_blank: _('Please select...'), class: 'form-control js-jobs-to-be-done-dropdown'
.row .row
.form-group.col-sm-12.js-jobs-to-be-done-other-group.hidden .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)') = label_tag :jobs_to_be_done_other, _('Why are you signing up? (Optional)')
......
...@@ -135,7 +135,8 @@ RSpec.describe Registrations::WelcomeController do ...@@ -135,7 +135,8 @@ RSpec.describe Registrations::WelcomeController do
user: { user: {
role: 'software_developer', role: 'software_developer',
setup_for_company: setup_for_company, setup_for_company: setup_for_company,
email_opted_in: email_opted_in email_opted_in: email_opted_in,
registration_objective: 'code_storage'
} }
} }
end end
...@@ -179,6 +180,14 @@ RSpec.describe Registrations::WelcomeController do ...@@ -179,6 +180,14 @@ RSpec.describe Registrations::WelcomeController do
allow(::Gitlab).to receive(:com?).and_return(true) allow(::Gitlab).to receive(:com?).and_return(true)
end 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 setup for company is false' do
context 'when the user opted in' do context 'when the user opted in' do
let(:email_opted_in) { '1' } let(:email_opted_in) { '1' }
......
...@@ -59,7 +59,7 @@ RSpec.describe 'Welcome screen', :js do ...@@ -59,7 +59,7 @@ RSpec.describe 'Welcome screen', :js do
it 'allows specifying other for the jobs_to_be_done experiment', :experiment 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)') 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)') expect(page).to have_content('Why are you signing up? (Optional)')
......
...@@ -9,25 +9,17 @@ RSpec.describe EE::RegistrationsHelper do ...@@ -9,25 +9,17 @@ RSpec.describe EE::RegistrationsHelper do
end end
end end
describe '#shuffled_jobs_to_be_done_options' do describe '#shuffled_registration_objective_options' do
subject { helper.shuffled_jobs_to_be_done_options } 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 expect(shuffled_option_values).to contain_exactly(*UserDetail.registration_objectives.keys)
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)
end end
it '"other" is always the last option' do 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 end
end end
...@@ -66,7 +66,7 @@ RSpec.describe 'registrations/welcome/show' do ...@@ -66,7 +66,7 @@ RSpec.describe 'registrations/welcome/show' do
let_it_be(:stubbed_experiments) { { jobs_to_be_done: :candidate } } let_it_be(:stubbed_experiments) { { jobs_to_be_done: :candidate } }
it 'renders a select and text field for additional information' do 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) is_expected.to have_selector('input[name="jobs_to_be_done_other"]', visible: false)
end end
end end
......
...@@ -11,6 +11,8 @@ RSpec.describe NamespaceSetting, type: :model do ...@@ -11,6 +11,8 @@ RSpec.describe NamespaceSetting, type: :model do
it { is_expected.to belong_to(:namespace) } it { is_expected.to belong_to(:namespace) }
end 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 "validations" do
describe "#default_branch_name_content" do describe "#default_branch_name_content" do
let_it_be(:group) { create(:group) } let_it_be(:group) { create(:group) }
......
...@@ -4,6 +4,7 @@ require 'spec_helper' ...@@ -4,6 +4,7 @@ require 'spec_helper'
RSpec.describe UserDetail do RSpec.describe UserDetail do
it { is_expected.to belong_to(:user) } 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 'validations' do
describe '#job_title' do describe '#job_title' do
......
...@@ -79,6 +79,9 @@ RSpec.describe User 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).allow_nil }
it { is_expected.to delegate_method(:bio=).to(:user_detail).with_arguments(:args).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 end
describe 'associations' do 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