Adding flush so models in registry are always fresh

fixes issues baking model + test
This commit is contained in:
mark_story 2009-05-26 00:36:25 -04:00
parent fe235f4e94
commit 2b6ea8748c
2 changed files with 25 additions and 0 deletions

View file

@ -237,6 +237,7 @@ class TestTask extends Shell {
* @return object
**/
function &buildTestSubject($type, $class) {
ClassRegistry::flush();
App::import($type, $class);
$class = $this->getRealClassName($type, $class);
if (strtolower($type) == 'model') {

View file

@ -228,6 +228,30 @@ class TestTaskTest extends CakeTestCase {
$this->assertEqual($result, $this->Task->classTypes[1]);
}
/**
* creating test subjects should clear the registry so the registry is always fresh
*
* @return void
**/
function testRegistryClearWhenBuildingTestObjects() {
ClassRegistry::flush();
$model = ClassRegistry::init('TestTaskComment');
$model->bindModel(array(
'belongsTo' => array(
'Random' => array(
'className' => 'TestTaskArticle',
'foreignKey' => 'article_id',
)
)
));
$keys = ClassRegistry::keys();
$this->assertTrue(in_array('random', $keys));
$object =& $this->Task->buildTestSubject('Model', 'TestTaskComment');
$keys = ClassRegistry::keys();
$this->assertFalse(in_array('random', $keys));
}
/**
* test that getClassName returns the user choice as a classname.
*