Skip to content

Commit

Permalink
Updating tests for ModelTask. Making it impossible to bake a model wh…
Browse files Browse the repository at this point in the history
…ich does not have a table on the active connection. Fixes #6035
  • Loading branch information
markstory committed Jul 9, 2009
1 parent 9bbb33e commit 7e1f9ee
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
6 changes: 5 additions & 1 deletion cake/console/libs/tasks/model.php
Expand Up @@ -197,6 +197,10 @@ function __interactive() {
if (!array_key_exists('id', $fields)) {
$primaryKey = $this->findPrimaryKey($fields);
}
} else {
$this->err(sprintf(__('Table %s does not exist, cannot bake a model without a table.', true), $useTable));
$this->_stop();
return false;
}
$displayField = $tempModel->hasField(array('name', 'title'));
if (!$displayField) {
Expand Down Expand Up @@ -243,7 +247,7 @@ function __interactive() {

$this->hr();
$looksGood = $this->in(__('Look okay?', true), array('y','n'), 'y');

if (strtolower($looksGood) == 'y') {
$vars = compact('associations', 'validate', 'primaryKey', 'useTable', 'displayField');
$vars['useDbConfig'] = $this->connection;
Expand Down
26 changes: 25 additions & 1 deletion cake/tests/cases/console/libs/tasks/model.test.php
Expand Up @@ -698,18 +698,42 @@ function testExecuteIntoAll() {
function testExecuteIntoInteractive() {
$this->Task->connection = 'test_suite';
$this->Task->path = '/my/path/';
$this->Task->interactive = true;

$this->Task->setReturnValueAt(0, 'in', '1'); //choose article
$this->Task->setReturnValueAt(1, 'in', 'n'); //no validation
$this->Task->setReturnValueAt(2, 'in', 'y'); //yes to associations
$this->Task->setReturnValueAt(3, 'in', 'y'); //yes to comment relation
$this->Task->setReturnValueAt(4, 'in', 'y'); //yes to user relation
$this->Task->setReturnValueAt(5, 'in', 'y'); //yes to tag relation
$this->Task->setReturnValueAt(6, 'in', 'n'); //no to looksGood?
$this->Task->setReturnValueAt(6, 'in', 'n'); //no to additional assocs
$this->Task->setReturnValueAt(7, 'in', 'y'); //yes to looksGood?
$this->Task->setReturnValue('_checkUnitTest', true);

$this->Task->Test->expectOnce('bake');
$this->Task->Fixture->expectOnce('bake');

$filename = '/my/path/article.php';
$this->Task->expectOnce('createFile');
$this->Task->expectAt(0, 'createFile', array($filename, new PatternExpectation('/class Article/')));
$this->Task->execute();
}

/**
* test using bake interactively with a table that does not exist.
*
* @return void
**/
function testExecuteWithNonExistantTableName() {
$this->Task->connection = 'test_suite';
$this->Task->path = '/my/path/';

$this->Task->expectOnce('_stop');
$this->Task->expectOnce('err');

$this->Task->setReturnValueAt(0, 'in', 'Foobar');
$this->Task->setReturnValueAt(1, 'in', 'y');
$this->Task->execute();
}
}
?>

0 comments on commit 7e1f9ee

Please sign in to comment.