diff options
author | Michael Kozono <mkozono@gmail.com> | 2017-08-07 18:49:54 -0700 |
---|---|---|
committer | Michael Kozono <mkozono@gmail.com> | 2017-08-07 19:30:05 -0700 |
commit | 4fc2db3457ee5a29d70ef943b8071068a5a379ed (patch) | |
tree | c8394c2c218fa4574b2face9e68d9f23593cabdd | |
parent | 457fc3e287fff6b15e64a1cd0f59ec2296ce4a93 (diff) | |
download | gitlab-ce-4fc2db3457ee5a29d70ef943b8071068a5a379ed.tar.gz |
Save opted_in_to_emails checkbox on sign up
-rw-r--r-- | app/controllers/registrations_controller.rb | 2 | ||||
-rw-r--r-- | app/services/users/build_service.rb | 3 | ||||
-rw-r--r-- | app/views/devise/shared/_signup_box.html.haml | 4 | ||||
-rw-r--r-- | spec/features/signup_spec.rb | 67 |
4 files changed, 74 insertions, 2 deletions
diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index 1bc6520370a..153aee6e710 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -52,7 +52,7 @@ class RegistrationsController < Devise::RegistrationsController private def sign_up_params - params.require(:user).permit(:username, :email, :email_confirmation, :name, :password) + params.require(:user).permit(:username, :email, :email_confirmation, :name, :password, :email_opted_in) end def resource_name diff --git a/app/services/users/build_service.rb b/app/services/users/build_service.rb index ff234a3440f..0a3148b033c 100644 --- a/app/services/users/build_service.rb +++ b/app/services/users/build_service.rb @@ -74,7 +74,8 @@ module Users :password_automatically_set, :name, :password, - :username + :username, + :email_opted_in ] end diff --git a/app/views/devise/shared/_signup_box.html.haml b/app/views/devise/shared/_signup_box.html.haml index 298604dee8c..42ebb2e074e 100644 --- a/app/views/devise/shared/_signup_box.html.haml +++ b/app/views/devise/shared/_signup_box.html.haml @@ -22,6 +22,10 @@ = 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 + - 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" %div - if Gitlab::Recaptcha.enabled? = recaptcha_tags diff --git a/spec/features/signup_spec.rb b/spec/features/signup_spec.rb index b6367b88e17..7b9dc591ddc 100644 --- a/spec/features/signup_spec.rb +++ b/spec/features/signup_spec.rb @@ -2,6 +2,73 @@ require 'spec_helper' feature 'Signup' do describe 'signup with no errors' 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 + context "when sending confirmation email" do before do stub_application_setting(send_user_confirmation_email: true) |