Returning response objects from controllers wasn't working correctly.

This commit is contained in:
mark_story 2011-07-09 14:21:32 -04:00 committed by mark_story
parent 177cd39abb
commit c25394278b
2 changed files with 29 additions and 1 deletions

View file

@ -110,12 +110,14 @@ class Dispatcher {
$controller->constructClasses(); $controller->constructClasses();
$controller->startupProcess(); $controller->startupProcess();
$render = true;
$result = $controller->invokeAction($request); $result = $controller->invokeAction($request);
if ($result instanceof CakeResponse) { if ($result instanceof CakeResponse) {
$render = false;
$response = $result; $response = $result;
} }
if ($controller->autoRender) { if ($render && $controller->autoRender) {
$response = $controller->render(); $response = $controller->render();
} elseif ($response->body() === null) { } elseif ($response->body() === null) {
$response->body($result); $response->body($result);

View file

@ -167,6 +167,15 @@ class SomePagesController extends AppController {
return true; return true;
} }
/**
* Test method for returning responses.
*
* @return CakeResponse
*/
public function responseGenerator() {
return new CakeResponse(array('body' => 'new response'));
}
/** /**
* redirect method overriding * redirect method overriding
* *
@ -806,6 +815,23 @@ class DispatcherTest extends CakeTestCase {
$this->assertEqual($controller->params['pass'][0], 'something. .', 'Period was chopped off. %s'); $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 * testAdminDispatch method
* *