[Rails] Functional Test Problem. Nubee, please help

Brian Hughes
Thu, 27 Apr 2006 21:40:59 -0000

On Apr 27, 2006, at 05:27 PM, Allen wrote:
> But if i am in my ActivitiesController functional test, then a call
> to :
>
> post :login, :user => {:name => "fred", :password =>
"abracadabra"}
>
> will post to the login action of ActivitiesController and not
> LoginController.  Do you see my problem?

Well, yes and no. Obviously, if you aren''t in the LoginController,
you don''t want to be sending a post to one of its actions.

But, in order to test your ActivitiesController you need to be an
already logged in user when you call the action. As long as your
LoginController sets one, or more, values in the session object that
signifies you are logged in, then you don''t really have a problem.
Simply pass those same values as part of the get call:

   get :index, {}, {:logged_in => true}

Where the second hash that you pass to get/post/put/delete/head
contains the values you want to seed into the session object...

-Brian