I saw that you can just manipulate the session data to handle this, and
that is simpler.
But of course, I'm stubborn and I preferred the idea of actually "doing"
the login as part of the functional test.
I have worked around it, and here's the code that does it:
def login(user = 'blah', password = 'blah')
old_controller = @controller
@controller = AccountController.new
post :login, :login => user, :password => password
assert_equal(flash[:notice], "Logged in successfully", "Should be
@controller = old_controller
#This allows the debug_request and debug_response methods to be used
in a multi-request functional test
#and actually show the correct information.
#Store the current request
@previous_request = @request
#Make new request and response objects
@controller.request = @request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new
#Move the session data over so we don't lose any context.
@previous_request.session.data.each do |k, v|
@request.session[k] = v
The "login" method calls "reset_request_and_response" which creates a
new TestRequest and TestResponse and moves the session data over so
that, among other things, the request knows that it is still logged in.
Then the dumps of the request and response look correct given the
request that I'm really interested in.
Also, now you could have multi-request functional tests if you wanted to
(although strictly speaking, you probably shouldn't since each test
should test only one interaction).