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/HowtoUseUrlHelpersWithActionMailer 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
I found a way round this by patching actioncontroller::base http://dev.rubyonrails.org/ticket/3517 CHEERS> SAM Sam Joseph wrote:>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/HowtoUseUrlHelpersWithActionMailer > >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 > >_______________________________________________ >Rails mailing list >Rails@lists.rubyonrails.org >http://lists.rubyonrails.org/mailman/listinfo/rails > > > >