From 7f14c7ff2f394f6cbb1768582a0af80559a79a49 Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 13 Dec 2019 17:17:39 +0000 Subject: [PATCH] # This is a combination of 3 commits. # This is the 1st commit message: Added email signup test Fixed spamaway shortcircuiting Renamed signup_flow file and fixed grammar Added email signup test Renamed signup_flow file and fixed grammar Fixed spamaway shortcircuiting Added email signup test Renamed signup_flow file and fixed grammar Added email signup test Renamed signup_flow file and fixed grammar Undid changes to users controller Fixed travis build error Fixed travis build errors # This is the commit message #2: Added email signup test # This is the commit message #3: Fixed spamaway shortcircuiting --- app/controllers/users_controller.rb | 4 ++- test/integration/signup_flow_email_test.rb | 32 ++++++++++++++++++++++ test/integration/signup_flow_test.rb | 32 ++++++++++++++++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 test/integration/signup_flow_email_test.rb create mode 100644 test/integration/signup_flow_test.rb diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index c633b4df48a..910c3bea11b 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -14,7 +14,9 @@ def create using_recaptcha = !params[:spamaway] && Rails.env == "production" recaptcha = verify_recaptcha(model: @user) if using_recaptcha @spamaway = Spamaway.new(spamaway_params) unless using_recaptcha - if ((@spamaway&.valid?) || recaptcha) && @user.save + + saved = @user.save + if ((@spamaway&.valid?) || recaptcha) && saved if current_user.crypted_password.nil? # the user has not created a pwd in the new site flash[:warning] = I18n.t('users_controller.account_migrated_create_new_password') redirect_to "/profile/edit" diff --git a/test/integration/signup_flow_email_test.rb b/test/integration/signup_flow_email_test.rb new file mode 100644 index 00000000000..869d2b67d0e --- /dev/null +++ b/test/integration/signup_flow_email_test.rb @@ -0,0 +1,32 @@ +require 'test_helper' + + +class SignUpTest < ActionDispatch::IntegrationTest + def setup + @new_user = { + :username => "newuser", + :email => "newuser@gmail.com", + :password => "validpassword" + } + end + + test 'display email error messages' do + post '/register', params: { + user: { + username: @new_user[:username], + email: 'notanemail', + password: @new_user[:password], + password_confirmation: @new_user[:password], + }, + spamaway: { + statement1: I18n.t('spamaway.human.statement1'), + statement2: I18n.t('spamaway.human.statement1'), + statement3: I18n.t('spamaway.human.statement1'), + statement4: I18n.t('spamaway.human.statement1') + } + } + + # assert response.body.include? '1 error prohibited this user from being saved' + assert response.body.include? 'Email should look like an email address.' + end +end diff --git a/test/integration/signup_flow_test.rb b/test/integration/signup_flow_test.rb new file mode 100644 index 00000000000..f795dd7f6b2 --- /dev/null +++ b/test/integration/signup_flow_test.rb @@ -0,0 +1,32 @@ +re 'test_helper' + + +class SignUpTest < ActionDispatch::IntegrationTest + def setup + @new_user = { + :username => "newuser", + :email => "newuser@gmail.com", + :password => "validpassword" + } + end + + test 'email error messages' do + post '/register', params: { + user: { + username: @new_user[:username], + email: 'notanemail', + password: @new_user[:password], + password_confirmation: @new_user[:password], + }, + spamaway: { + statement1: I18n.t('spamaway.human.statement1'), + statement2: I18n.t('spamaway.human.statement1'), + statement3: I18n.t('spamaway.human.statement1'), + statement4: I18n.t('spamaway.human.statement1') + } + } + + assert response.body.include? '1 errors prohibited this user from being saved' + assert response.body.include? 'Email should look like an email address.' + end +end