[Rails] Functional Test Problem. Nubee, please help

Brian Hughes
Thu, 27 Apr 2006 21:12:25 -0000

On Apr 27, 2006, at 04:44 PM, Allen 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!

You can pass several hashes to all of the request methods: params,
session and flash. From the AWDR chapter on Testing, specifically
Testing Controllers:

   get/post/put/delete/head(action, parameters=nil, session=nil,
flash=nil)

   Examples:
   get :index
   post :login, :user => {:name => "fred", :password =>
"abracadabra"}

-Brian