April 27, 2006...8:02 pm

Testing the controller

Jump to Comments

A couple things I found very handy today while setting up a functional test for a controller.

First off, this controller relies on a user being logged in (but this isn't the controller that actually manages the login process).

The easiest way I found to make sure that I was properly logged in was to temporarily change @controller to the UserController — login — then change back. Like this:

controllerswap.png

A handy pointer regarding testing instance variables from Jeremy Kemper.

To access an instance variable in the controller that you are testing: simply examine what would have been sent to the view, in the response:

something = @response.template.assigns['something'] 


Leave a Reply