Topic: Testing controllers which require authentication

I'm using acts_as_authenticated to manage users and so, have an account controller which has the login function which then redirects to an admin controller (all actions in the admin controller are protected with before_filter :login_required).

Acts_as_authenticated made a account_controller_test for me which has the login test in, but then in my admin controller test, how do I make it so that a user is logged in before any of the admin controller tests are run?

Re: Testing controllers which require authentication

I've not used acts_as_authenticated, but I'm assuming it uses a session object to tell whether you're logged in.  Find out what that is and pass it to the get an post calls thusly...

post :add_topic, {}, :current_user => @user

...where :current_user is the name of the session variable.

Re: Testing controllers which require authentication

I should've searched just a little longer before I posted here. I just needed to dig into the lib folder and found authenticated_test_helper.rb which has a method for doing just what I need. smile

cheers for the halp anyway..

Re: Testing controllers which require authentication

Hi,

I'm currently trying to figure this out myself. I've tried running the login_as and authorize_as in the first part of the create_user test method, but this isn't working for me. I even set the user session variable to the correct value and still not working.