Test registration e-mail

This commit is contained in:
cryptogopher 2023-04-19 00:31:52 +02:00
parent 4a1fe657c0
commit 2d95b11a34
4 changed files with 19 additions and 2 deletions

View File

@ -34,7 +34,7 @@ module FixinMe
# SETUP: Below settings need to be updated on a per-installation basis.
#
# URL to use in sent e-mails.
config.action_mailer.default_url_options = {host: 'localhost'}
config.action_mailer.default_url_options = {host: 'localhost', :protocol => 'https'}
# https://guides.rubyonrails.org/configuring.html#config-action-mailer-delivery-method
config.action_mailer.delivery_method = :sendmail

View File

@ -39,6 +39,7 @@ Rails.application.configure do
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.delivery_method = :test
config.action_mailer.default_url_options = {host: '127.0.0.1', :protocol => 'http'}
# Print deprecation notices to the stderr.
config.active_support.deprecation = :stderr

View File

@ -28,15 +28,26 @@ class UsersTest < ApplicationSystemTestCase
test "register" do
visit new_user_session_url
click_link t(:register)
fill_in User.human_attribute_name(:email).capitalize, with: random_email
password = random_password
fill_in User.human_attribute_name(:password).capitalize, with: password
fill_in t('users.registrations.new.password_confirmation'), with: password
assert_difference ->{User.count}, 1 do
assert_emails 1 do
click_on t(:register)
end
end
assert_no_current_path new_user_registration_path
assert_text t('devise.registrations.signed_up_but_unconfirmed')
with_last_email do |mail|
visit Capybara.string(mail.body.to_s).find_link("Confirm my account")[:href]
end
assert_current_path new_user_session_path
assert_text t('devise.confirmations.confirmed')
assert User.last.confirmed?
end
#test "visiting the index" do

View File

@ -10,6 +10,7 @@ class ActiveSupport::TestCase
fixtures :all
include AbstractController::Translation
include ActionMailer::TestHelper
def randomize_user_password!(user)
random_password.tap { |p| user.update!(password: p) }
@ -22,4 +23,8 @@ class ActiveSupport::TestCase
def random_email
"%s@%s.%s" % (1..3).map { SecureRandom.alphanumeric(rand(1..20)) }
end
def with_last_email
yield(ActionMailer::Base.deliveries.last)
end
end