Routes in Functional Tests?

Hello Rails Talk,

How do I get named routes in my functional tests? I am testing a
mailer and want to check for a URL in the email:

:: user_mailer_test.rb ::
require File.dirname(FILE) + ‘/…/test_helper’
require ‘user_mailer’

class UserMailerTest < Test::Unit::TestCase

FIXTURES_PATH = File.dirname(FILE) + ‘/…/fixtures’

CHARSET = “utf-8”

include ActionMailer::Quoting

def setup
ActionMailer::Base.delivery_method = :test
ActionMailer::Base.perform_deliveries = true
ActionMailer::Base.deliveries = []
@expected = TMail::Mail.new
@expected.set_content_type “text”, “plain”, { “charset” =>
CHARSET }
end

def test_confirmation_sent
user = create_user
email = UserMailer.create_signup_notification(user)
assert_match(‘http://#{HOST}/’ +
@controller.activate_path(user.activation_code), email.body)
end
end

Regards,
–Dean

Forgot to say that this test fails like this:

  1. Error:
    test_confirmation_sent(BrewerMailerTest):
    NoMethodError: You have a nil object when you didn’t expect it!
    The error occurred while evaluating nil.activate_path
    ./test/functional/brewer_mailer_test.rb:21:in
    `test_confirmation_sent’

Regards,
–Dean

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs