functional testing woes

hey all,

finished coding unit tests for a rails app and am moving on to the next
step to try to give the code to test code ratio a bit of a boost. can't
figure out how to test some of the stuff the way its implemented and
also have some general confusion about the more common aspects.

first the more common: in the agile web dev book (1st ed) it shows how
you can write a login method in the test_helper.rb and then you can use
that from therein when testing stuff that requires the user to be
logged in.. ok so this only works for the controller that the login
method is inside of ?? (not the test helper but the actual login

writing the functional test for the login controller doesn't seem too
bad, but does this mean for every other controller that you need to be
logged in to use needs to be passed the session variables to make it
look like the user is logged in? i can't do something like post
:controller => login, :action => login so the helper could be used in
all functional tests?

next question, my app required some more advanced interface stuff..
basically there's tabs with different pages/forms and when switching
tabs the current state of the form is saved into a serializable session
object before changing tabs. because of the demanding interface i put
all that sort of functionality into an 'interface' controller.. so if i
want to write a functional test for checking functionality of the
customer controller code (forms and screens for customer data) i can't
call the interface methods. what do i do? test what i can by only
calling stuff in the controller in question and leave the rest to
integration tests (that's what their called right?)


For testing controllers which require login, there was a thread earlier on this list, search for the thread “Testing Actions Requiring A Login”.

thanks that helped..

one more question:
if i have an action that redirects to another action and i test this to
be true with an assert_redirected_to shouldn't the code in the action
that its being redirected to get run also? because the action that my
code is redirected to is supposed to create a new user, but when i look
in the session for the user id its not there and when i look in the
table its not there either.. do i have to do another 'get' to have the
code in the next action run?


Hi --

that's not what i'm experiencing right now.. looked in the logs and i
see the redirect and the 302, but code in the action doesn't seem to
come up in the log. i just did a 'get' for the page and things are
working as they should..

it seems like i go just a little ways before something else pops up..
i'm passing an active record object in the flash (its unsaved that's
why i didn't pass the id and i put it in the flash instead of params
because at the time i didn't know any better).. seems like passing the
object in the flash preserves the attributes fine, but unlike the
actual rails app the copy that goes in the flash does not preserve the
values stored in the object attr_accessors. any ideas? i guess i could
switch it over to use params hash instead of flash hash, but shouldn't
this work?


Q. What’s a good holiday present for the serious Rails developer?
A. RUBY FOR RAILS by David A. Black (
aka The Ruby book for Rails developers!
Q. Where can I get Ruby/Rails on-site training, consulting, coaching?
A. Ruby Power and Light, LLC (

Mr. Black, I love your new sig :wink:

This should also be included in the FAQ of the Rails list. Faisal, are you listening?