I’ve been Googling this one for a while now, and haven’t found a
satisfactory answer. It has been posted here before by someone else,
but it seems to have got forgotten, so here goes - perhaps someone can
think up a way around the problem?
In ApplicationController, I have the following method:
class ApplicationController < ActionController::Base
Discover whether the currently logged user is an admin user
This method works fine in various views, but I can’t seem to test it.
Rails doesn’t generate a test file for ApplicationController, so I
have done that:
require File.dirname(FILE) + ‘/…/test_helper’
Re-raise errors caught by the controller.
class ApplicationController; def rescue_action(e) raise e end; end
class ApplicationControllerTest < Test::Unit::TestCase
@controller = ApplicationController.new
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
# Don’t know how to test “admin?”
I can run this test successfully, but if I include a call to admin?, I
get a NoMethodError. I also get the same thing if I try testing it in
another controller (which inherits from application.rb).