[Rails] Functional Test Problem. Nubee, please help

Wilson Bilkovich
Thu, 27 Apr 2006 21:46:49 -0000

On 4/27/06, Allen <e@t.com> wrote:
> ALl my controllers require the user to be logged in.  SO they will be
> redirected to my "login" controller.
>
> How do i login first in a functional test?  Im assuming i use the setup
> method to login the controller.
>
> This is the setup method for the Activities controller functional test:
>
>   def setup
>     @controller = ActivitiesController.new
>     @request    = ActionController::TestRequest.new
>     @response   = ActionController::TestResponse.new
>   end
>
> my "login" controller has a method "authenticate" which
needs
> params[:username] and params[:password].  Please help!
>
> Thanks
> Allen
>

Since you''re going to be testing the actual login process in the
functional tests for your login controller, you might as well just
bypass it elsewhere.

In the setup method, you can say:
@request.session[:user] = User.new :name => ''Superhacker''
(or whatever the particulars of your login system require.)