Skip to content

Commit

Permalink
# This is a combination of 3 commits.
Browse files Browse the repository at this point in the history
# 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 publiclab#2:

Added email signup test

# This is the commit message publiclab#3:

Fixed spamaway shortcircuiting
  • Loading branch information
chen-robert committed Dec 14, 2019
1 parent 9f0d400 commit 7f14c7f
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 1 deletion.
4 changes: 3 additions & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
32 changes: 32 additions & 0 deletions test/integration/signup_flow_email_test.rb
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions test/integration/signup_flow_test.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 7f14c7f

Please sign in to comment.