Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Returning response objects from controllers wasn't working correctly.

  • Loading branch information...
commit c25394278b6847e1d99052b9dd58ca8a4359b125 1 parent 177cd39
Mark Story markstory authored markstory committed
4 lib/Cake/Routing/Dispatcher.php
View
@@ -110,12 +110,14 @@ protected function _invoke(Controller $controller, CakeRequest $request, CakeRes
$controller->constructClasses();
$controller->startupProcess();
+ $render = true;
$result = $controller->invokeAction($request);
if ($result instanceof CakeResponse) {
+ $render = false;
$response = $result;
}
- if ($controller->autoRender) {
+ if ($render && $controller->autoRender) {
$response = $controller->render();
} elseif ($response->body() === null) {
$response->body($result);
26 lib/Cake/Test/Case/Routing/DispatcherTest.php
View
@@ -168,6 +168,15 @@ protected function _protected() {
}
/**
+ * Test method for returning responses.
+ *
+ * @return CakeResponse
+ */
+ public function responseGenerator() {
+ return new CakeResponse(array('body' => 'new response'));
+ }
+
+/**
* redirect method overriding
*
* @return void
@@ -807,6 +816,23 @@ public function testDispatchBasic() {
}
/**
+ * Test that Dispatcher handles actions that return response objects.
+ *
+ * @return void
+ */
+ public function testDispatchActionReturnsResponse() {
+ $Dispatcher = new Dispatcher();
+ $request = new CakeRequest('some_pages/responseGenerator');
+ $response = $this->getMock('CakeResponse', array('_sendHeader'));
+
+ ob_start();
+ $Dispatcher->dispatch($request, $response);
+ $result = ob_get_clean();
+
+ $this->assertEquals('new response', $result);
+ }
+
+/**
* testAdminDispatch method
*
* @return void
Please sign in to comment.
Something went wrong with that request. Please try again.