Forum: Ruby on Rails testing UrlHelper in ActionMailer

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Cb33b32bd5d675db7be148542976e510?d=identicon&s=25 Sam Joseph (Guest)
on 2006-01-09 22: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:

http://wiki.rubyonrails.com/rails/pages/HowtoUseUr...

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
perhaps?
Some method to set the controllers @url variable ...?

I was trying this:

class MockController < ActionController::Base
@url =
ActionController::UrlRewriter.new(ActionController::TestRequest.new,
nil)
end

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.

CHEERS> SAM
Cb33b32bd5d675db7be148542976e510?d=identicon&s=25 Sam Joseph (Guest)
on 2006-01-17 18:55
(Received via mailing list)
I found a way round this by patching actioncontroller::base

http://dev.rubyonrails.org/ticket/3517

CHEERS> SAM
This topic is locked and can not be replied to.