samedi 15 août 2020

Rails password reset mailer test undefined method `html_safe' error (using Clearance gem)

I'm trying to create a mailer test in Rails to check the password reset mailer that Clearance sends.

The default view for the password reset mailer has this link in it:

<%= link_to "Change my password",
    edit_user_password_url(@user, token: @user.confirmation_token.html_safe) %>

It seems like calling html_safe is a good thing, but in my mailer test I keep getting this error:

Minitest::UnexpectedError: ActionView::Template::Error: undefined method `html_safe' for nil:NilClass
Did you mean?  html_safe?

I can't figure out why this is happening. Here's my mailer test so far:

require "test_helper"

class PasswordResetMailerTest < ActionMailer::TestCase
  setup do
    @user = users(:elvis)
  end

  test "password reset email" do
    email = ClearanceMailer.change_password(@user)

    # Send the email, then test that it got queued
    assert_emails 1 do
      email.deliver_now
    end
  end
end

Why is that causing an undefined method html_safe error?

Aucun commentaire:

Enregistrer un commentaire