Routes in Functional Tests?

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:inactivate_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:inmethod_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:inrun’

What is it about the get call that “turns on” the named route?

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