Can't test application controller methods in functional tests?

I have two methods in application controller that I want to test from
ForumController:


class ApplicationController < ActionController::Base

def logout
session[:username] = nil
session[:admin] = nil
redirect_to(request.request_uri)
end

def home
redirect_to(:controller => ‘forum’, :action => ‘list_forum’)
end

class ForumController < ApplicationController
layout “forum”

end

For method home, action list_forum works according to my test, so that
shouldn’t be the problem. The corresponding tests gives errors:


require File.dirname(FILE) + ‘/…/test_helper’
require ‘forum_controller’

Re-raise errors caught by the controller.

class ForumController; def rescue_action(e) raise e end; end

class ForumControllerTest < Test::Unit::TestCase
#add fixtures:
fixtures :messages, :message_threads, :message_boards, :forums

def setup
@controller = ForumController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
end

test logout (all cases)

def test_logout
get :logout, nil, nil
assert_response :success
assert_nil session[:username]
assert_nil session[:admin]

get :logout, nil, {:username => 'bogus'}
assert_response :success
assert_nil session[:username]
assert_nil session[:admin]

get :logout, nil, {:username => 'Admin', :admin => 1}
assert_response :success
assert_nil session[:username]
assert_nil session[:admin]

end

test home

def test_home
get :home
assert_response :success
assert_redirected_to ‘list_forum’
assert_not_nil assigns[“forums”]
end
end

  1. Error:
    test_home(ForumControllerTest):
    ActionController::RoutingError: No route matches
    {:action=>“home”, :controller=>“forum”}
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/
    action_controller/routing.rb:1299:in generate' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/ action_controller/routing.rb:1244:ingenerate_extras’
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/
    action_controller/routing.rb:1240:in extra_keys' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/ action_controller/test_process.rb:105:inassign_parameters’
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/
    action_controller/test_process.rb:380:in process' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/ action_controller/test_process.rb:356:inget’
    forum_controller_test.rb:464:in `test_home’

  2. Error:
    test_logout(ForumControllerTest):
    ActionController::RoutingError: No route matches
    {:action=>“logout”, :controller=>“forum”}
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/
    action_controller/routing.rb:1299:in generate' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/ action_controller/routing.rb:1244:ingenerate_extras’
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/
    action_controller/routing.rb:1240:in extra_keys' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/ action_controller/test_process.rb:105:inassign_parameters’
    /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/
    action_controller/test_process.rb:380:in process' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/ action_controller/test_process.rb:356:inget’
    forum_controller_test.rb:446:in `test_logout’


What’s up with that? Can I not test ApplicationController methods in
ForumController?

Also, how can I set requested uri?

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