diff --git a/lib/Cake/Routing/Dispatcher.php b/lib/Cake/Routing/Dispatcher.php index 90a70a039..0203b9ff1 100644 --- a/lib/Cake/Routing/Dispatcher.php +++ b/lib/Cake/Routing/Dispatcher.php @@ -110,12 +110,14 @@ class Dispatcher { $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); diff --git a/lib/Cake/Test/Case/Routing/DispatcherTest.php b/lib/Cake/Test/Case/Routing/DispatcherTest.php index 46de1d30a..1a039aa12 100644 --- a/lib/Cake/Test/Case/Routing/DispatcherTest.php +++ b/lib/Cake/Test/Case/Routing/DispatcherTest.php @@ -167,6 +167,15 @@ class SomePagesController extends AppController { return true; } +/** + * Test method for returning responses. + * + * @return CakeResponse + */ + public function responseGenerator() { + return new CakeResponse(array('body' => 'new response')); + } + /** * redirect method overriding * @@ -806,6 +815,23 @@ class DispatcherTest extends CakeTestCase { $this->assertEqual($controller->params['pass'][0], 'something. .', 'Period was chopped off. %s'); } +/** + * 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 *