Commit 4f0b3463 authored by Michael Kozono's avatar Michael Kozono

Save opted_in_to_emails checkbox on sign up

parent 4885e789
class RegistrationsController < Devise::RegistrationsController
include Recaptcha::Verify
prepend EE::RegistrationsController
def new
redirect_to(new_user_session_path)
......
module Users
class BuildService < BaseService
prepend ::EE::Users::BuildService
def initialize(current_user, params = {})
@current_user = current_user
@params = params.dup
......
......@@ -22,6 +22,7 @@
= f.label :password
= f.password_field :password, class: "form-control bottom", required: true, pattern: ".{#{@minimum_password_length},}", title: "Minimum length is #{@minimum_password_length} characters."
%p.gl-field-hint Minimum length is #{@minimum_password_length} characters
= render 'devise/shared/ee/email_opted_in', f: f
%div
- if Gitlab::Recaptcha.enabled?
= recaptcha_tags
......
module EE
module RegistrationsController
extend ActiveSupport::Concern
private
def sign_up_params
params.require(:user).permit(:username, :email, :email_confirmation, :name, :password, :email_opted_in)
end
end
end
module EE
module Users
module BuildService
private
def signup_params
[
:email,
:email_confirmation,
:password_automatically_set,
:name,
:password,
:username,
:email_opted_in
]
end
end
end
end
- if Gitlab.com?
.form-group
= f.check_box :email_opted_in
= f.label :email_opted_in, "I'd like to receive updates via email about GitLab."
require 'spec_helper'
feature 'Signup on EE' do
context 'for Gitlab.com' do
before do
expect(Gitlab).to receive(:com?).and_return(true).at_least(:once)
end
context 'when the user checks the opt-in to email updates box' do
it 'creates the user and sets the email_opted_in field truthy' do
user = build(:user)
visit root_path
fill_in 'new_user_name', with: user.name
fill_in 'new_user_username', with: user.username
fill_in 'new_user_email', with: user.email
fill_in 'new_user_email_confirmation', with: user.email
fill_in 'new_user_password', with: user.password
check 'new_user_email_opted_in'
click_button "Register"
user = User.find_by_username!(user.username)
expect(user.email_opted_in).to be_truthy
end
end
context 'when the user does not check the opt-in to email updates box' do
it 'creates the user and sets the email_opted_in field falsey' do
user = build(:user)
visit root_path
fill_in 'new_user_name', with: user.name
fill_in 'new_user_username', with: user.username
fill_in 'new_user_email', with: user.email
fill_in 'new_user_email_confirmation', with: user.email
fill_in 'new_user_password', with: user.password
click_button "Register"
user = User.find_by_username!(user.username)
expect(user.email_opted_in).to be_falsey
end
end
end
context 'not for Gitlab.com' do
before do
expect(Gitlab).to receive(:com?).and_return(false).at_least(:once)
end
it 'does not have a opt-in checkbox, it creates the user and sets email_opted_in to falsey' do
user = build(:user)
visit root_path
expect(page).not_to have_selector("[name='new_user_email_opted_in']")
fill_in 'new_user_name', with: user.name
fill_in 'new_user_username', with: user.username
fill_in 'new_user_email', with: user.email
fill_in 'new_user_email_confirmation', with: user.email
fill_in 'new_user_password', with: user.password
click_button "Register"
user = User.find_by_username!(user.username)
expect(user.email_opted_in).to be_falsey
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