Skip to content

Commit

Permalink
Controller::loadModel() now returns true when model is succesfully in…
Browse files Browse the repository at this point in the history
…stantiated as stated in docblock. Added test case.
  • Loading branch information
ADmad committed May 2, 2010
1 parent 257665e commit f386dca
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
6 changes: 4 additions & 2 deletions cake/libs/controller/controller.php
Expand Up @@ -607,7 +607,7 @@ function httpCodes($code = null) {
*
* @param string $modelClass Name of model class to load
* @param mixed $id Initial ID the instanced model class should have
* @return mixed true when single model found and instance created error returned if models not found.
* @return mixed true when single model found and instance created, error returned if model not found.
* @access public
*/
function loadModel($modelClass = null, $id = null) {
Expand Down Expand Up @@ -657,6 +657,8 @@ function loadModel($modelClass = null, $id = null) {
$this->_persist($modelClass, true, $object);
$this->modelNames[] = $modelClass;
}

return true;
}

/**
Expand Down Expand Up @@ -733,7 +735,7 @@ function redirect($url, $status = null, $exit = true) {
}

/**
* Convenience and object wrapper method for header(). Useful when doing tests and
* Convenience and object wrapper method for header(). Useful when doing tests and
* asserting that particular headers have been set.
*
* @param string $status The header message that is being set.
Expand Down
20 changes: 20 additions & 0 deletions cake/tests/cases/libs/controller/controller.test.php
Expand Up @@ -442,6 +442,26 @@ function endTest() {
App::build();
}

/**
* testLoadModel method
*
* @access public
* @return void
*/
function testLoadModel() {
$Controller =& new Controller();

$this->assertFalse(isset($Controller->ControllerPost));

$result = $Controller->loadModel('ControllerPost');
$this->assertTrue($result);
$this->assertTrue(is_a($Controller->ControllerPost, 'ControllerPost'));
$this->assertTrue(in_array('ControllerPost', $Controller->modelNames));

ClassRegistry::flush();
unset($Controller);
}

/**
* testConstructClasses method
*
Expand Down

0 comments on commit f386dca

Please sign in to comment.