From 1fd10c0935268e37c8f8d1d1b5787b5041eee2fd Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Fri, 12 Jan 2024 17:35:41 +0000 Subject: [PATCH] Test that signups can be confirmed and can authenticate afterwards --- test/integration/user_creation_test.rb | 27 ++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/test/integration/user_creation_test.rb b/test/integration/user_creation_test.rb index 8ec0dc9bc..e2d89f555 100644 --- a/test/integration/user_creation_test.rb +++ b/test/integration/user_creation_test.rb @@ -94,18 +94,29 @@ class UserCreationTest < ActionDispatch::IntegrationTest end end - # Check the e-mail - register_email = ActionMailer::Base.deliveries.first - - assert_equal register_email.to.first, new_email - # Check that the confirm account url is correct - assert_match(/#{@url}/, register_email.body.to_s) - - # Check the page assert_response :success assert_template "confirmations/confirm" + user = User.find_by(:email => "newtester@osm.org") + assert_not_nil user + assert_not_predicate user, :active? + + register_email = ActionMailer::Base.deliveries.first + assert_equal register_email.to.first, new_email + found_confirmation_url = register_email.parts.first.parts.first.to_s =~ %r{\shttp://test.host(/\S+)\s} + assert found_confirmation_url + confirmation_url = Regexp.last_match(1) ActionMailer::Base.deliveries.clear + + post confirmation_url + + assert_response :redirect + assert_redirected_to welcome_path + + user.reload + assert_predicate user, :active? + + assert_equal user, User.authenticate(:username => new_email, :password => "testtest") end def test_user_create_no_tou_failure -- 2.39.5