Simple testing question: Handling login in functional tests

When writing functional (e.g. controller unit) tests, I'm running into a
simple problem that I'm sure is very easy to fix, but I'm not sure of
the correct approach.

If I request a resource in my test case, via something like "get
:get_template" (where :get_template is an action on my controller), I
get a 302 and when I inspect the response, I see that it is redirecting
me to the login page (which makes sense since the :get_template action
is protected by authentication).

How do I handle the login requirement in my functional test? I use
acts_as_authenticated, which mandates an AccountController to manage
login, so by definition, I need to do something (meet the login
requirements) in another controller (Account) than the one I am testing.
Does that imply that I'm immediately in integration test territory?

Is there a simple way to manage it in the functional test? I considered
monkey patching the controller to skip the check_authorization
before_filter so that the test requests won't be redirected, but that
seems like it's overkill.


Generally, you'll need to mock out your login checks in your setup/before.

Just saw at Neeraj's site this morning:

-- Josh

Robby Russell wrote:

Just saw this at Neeraj's site this morning:

-- Josh

Robby Russell wrote:

I also found this approach which is interesting because it actually
forces a test of the login process each time.

Thanks for the responses.