Its very important to be able to test application_controller.rb since by default its sort of left out by windows but many people put lots of code there ( so am I)
create a test/functional/application_controller_test.rb file with following.
require File.dirname(__FILE__) + '/../test_helper'
require 'application'
require 'mocha'
# Re-raise errors caught by the controller.
class ApplicationController; def rescue_action(e) raise e end; end
class ApplicationControllerTest <Test::Unit::TestCase
def setup
@controller = ApplicationController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
end
#Sample Test
def test_that_test_can_get
assert_nothing_raised{get :index}
end
end
This way you’ll be able to use regular functional testing way calling your actions ( or methods of the application controller class). Also, you’ll be able to check you sessions, flashes e.t.c that will not be accessible other wise.
Sometimes I store filters that are used in many other controllers in the application controller for reusability. Filter, due to its nature does not render anything, so when you call it by get you will get missing template error. So i used assert_raises to show to other developers that this is something that will popup if filter called the way of get, but tests would pass normally.
assert_raises(ActionController::MissingTemplate){get :set_legal_entity_id_session_if_current_is_blank}