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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 On Feb 3, 9:57 pm, Dean <dean.brund...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I have the following: :: generic_controller.rb :: class GenericController < ApplicationController def activate end def index end end :: routes.rb :: ActionController::Routing::Routes.draw do |map| map.activate ''/activate/:activation_code'', :controller => ''generic'', :action => ''activate'' end :: generic_controller_test.rb :: require File.dirname(__FILE__) + ''/../test_helper'' class GenericControllerTest < ActionController::TestCase def test_activate_path get :index assert_not_nil activate_path("something") end end 0 remus test/functional % ruby generic_controller_test.rb Loaded suite generic_controller_test Started . Finished in 0.280308 seconds. 1 tests, 1 assertions, 0 failures, 0 errors If I comment out the get :index call in my test file, I get this: 0 remus test/functional % ruby generic_controller_test.rb Loaded suite generic_controller_test Started E Finished in 0.282201 seconds. 1) Error: test_activate_path(GenericControllerTest): NoMethodError: You have a nil object when you didn''t expect it! The error occurred while evaluating nil.rewrite /usr/lib64/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/base.rb:616:in `url_for'' (eval):17:in `activate_path'' /usr/lib64/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/ test_process.rb:463:in `send!'' /usr/lib64/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/ test_process.rb:463:in `method_missing'' generic_controller_test.rb:7:in `test_activate_path'' /usr/lib64/ruby/gems/1.8/gems/activesupport-2.0.2-/lib/active_support/ testing/default.rb:7:in `run'' What is it about the get call that "turns on" the named route? Regards, --Dean --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I have the following: :: generic_controller.rb :: class GenericController < ApplicationController def activate end def index end end :: routes.rb :: ActionController::Routing::Routes.draw do |map| map.activate ''/activate/:activation_code'', :controller => ''generic'', :action => ''activate'' end :: generic_controller_test.rb :: require File.dirname(__FILE__) + ''/../test_helper'' class GenericControllerTest < ActionController::TestCase def test_activate_path get :index assert_not_nil activate_path("something") end end 0 remus test/functional % ruby generic_controller_test.rb Loaded suite generic_controller_test Started . Finished in 0.280308 seconds. 1 tests, 1 assertions, 0 failures, 0 errors If I comment out the get :index call in my test file, I get this: 0 remus test/functional % ruby generic_controller_test.rb Loaded suite generic_controller_test Started E Finished in 0.282201 seconds. 1) Error: test_activate_path(GenericControllerTest): NoMethodError: You have a nil object when you didn''t expect it! The error occurred while evaluating nil.rewrite /usr/lib64/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/base.rb:616:in `url_for'' (eval):17:in `activate_path'' /usr/lib64/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/ test_process.rb:463:in `send!'' /usr/lib64/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/ test_process.rb:463:in `method_missing'' generic_controller_test.rb:7:in `test_activate_path'' /usr/lib64/ruby/gems/1.8/gems/activesupport-2.0.2-/lib/active_support/ testing/default.rb:7:in `run'' What is it about the get call that "turns on" the named route? Regards, --Dean --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---