module ActionController::TestCase::Behavior

def process_controller_response(action, cookies, xhr)

def process_controller_response(action, cookies, xhr)
  begin
    @controller.recycle!
    wrap_execution { @controller.dispatch(action, @request, @response) }
  ensure
    @request = @controller.request
    @response = @controller.response
    if @request.have_cookie_jar?
      unless @request.cookie_jar.committed?
        @request.cookie_jar.write(@response)
        cookies.update(@request.cookie_jar.instance_variable_get(:@cookies))
      end
    end
    @response.prepare!
    if flash_value = @request.flash.to_session_value
      @request.session["flash"] = flash_value
    else
      @request.session.delete("flash")
    end
    if xhr
      @request.delete_header "HTTP_X_REQUESTED_WITH"
      @request.delete_header "HTTP_ACCEPT"
    end
    @request.query_string = ""
    @response.sent!
  end
  @response
end