diff --git a/app/helpers/users_helper.rb b/app/helpers/users_helper.rb index c4d94758f..8c1ad5074 100644 --- a/app/helpers/users_helper.rb +++ b/app/helpers/users_helper.rb @@ -21,6 +21,6 @@ module UsersHelper end def email_verification_url(user) - verify_user_email_url(user, email_verification_key: user.email_address.verification_key) + verify_user_email_url(user, email_verification_key: user.email_address&.verification_key) end end diff --git a/test/unit/user_mailer_test.rb b/test/unit/user_mailer_test.rb index b01ae5564..25387a72a 100644 --- a/test/unit/user_mailer_test.rb +++ b/test/unit/user_mailer_test.rb @@ -48,6 +48,12 @@ class UserMailerTest < ActionMailer::TestCase mail = UserMailer.email_change_confirmation(@user) assert_emails(1) { mail.deliver_now } end + + should "not fail for a user without an email address" do + @user = create(:user) + mail = UserMailer.email_change_confirmation(@user) + assert_emails(0) { mail.deliver_now } + end end context "welcome_user method" do @@ -55,6 +61,12 @@ class UserMailerTest < ActionMailer::TestCase mail = UserMailer.welcome_user(@user) assert_emails(1) { mail.deliver_now } end + + should "not fail for a user without an email address" do + @user = create(:user) + mail = UserMailer.welcome_user(@user) + assert_emails(0) { mail.deliver_now } + end end end end