Forum: Ruby on Rails testing UrlHelper in ActionMailer

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Sam J. (Guest)
on 2006-01-09 23:00
(Received via mailing list)
Hi All,

So I found a helpful web page that explained how I could use things like
url_for in my mails:

However, I can't test them properly. The problem is that when I create a
controller in my unit tests and pass it into the ActionMailer, it's not
a real controller, set up as a controller is when it is instantiated via
an http request, so variables inside the controller like @url are not
set, meaning the test based version of the mail fails.

What I'm trying to do in the mail is something like this:

<%= url_for :controller => 'discussions', :action => 'tree', :id =>
@discussion %>

so I don't really need the defaults in the controller @url anyhow.

Any ideas how I can test this thing properly? Create a mock controller
Some method to set the controllers @url variable ...?

I was trying this:

class MockController < ActionController::Base
@url =,

but I keep getting "MissingSourceFile: No such file to load --
url_rewriter" errors - I can't work out how to pull in the UrlRewriter
class ...

Many thanks in advance.

Sam J. (Guest)
on 2006-01-17 19:55
(Received via mailing list)
I found a way round this by patching actioncontroller::base

This topic is locked and can not be replied to.