Skip to content

Commit

Permalink
adding models for schema generate
Browse files Browse the repository at this point in the history
  • Loading branch information
euromark committed Aug 8, 2012
1 parent 5e0e850 commit 62dee78
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/Cake/Console/Command/SchemaShell.php
Expand Up @@ -127,7 +127,9 @@ public function generate() {
$this->out(__d('cake_console', 'Generating Schema...'));
$options = array();
if ($this->params['force']) {
$options = array('models' => false);
$options['models'] = false;
} elseif (!empty($this->params['models'])) {
$options['models'] = String::tokenize($this->params['models']);
}

$snapshot = false;
Expand Down Expand Up @@ -464,6 +466,10 @@ public function getOptionParser() {
'short' => 's',
'help' => __d('cake_console', 'Snapshot number to use/make.')
);
$models = array(
'short' => 'm',
'help' => __d('cake_console', 'Specify models as comma separated list.'),
);
$dry = array(
'help' => __d('cake_console', 'Perform a dry run on create and update commands. Queries will be output instead of run.'),
'boolean' => true
Expand All @@ -489,7 +495,7 @@ public function getOptionParser() {
))->addSubcommand('generate', array(
'help' => __d('cake_console', 'Reads from --connection and writes to --path. Generate snapshots with -s'),
'parser' => array(
'options' => compact('plugin', 'path', 'file', 'name', 'connection', 'snapshot', 'force'),
'options' => compact('plugin', 'path', 'file', 'name', 'connection', 'snapshot', 'force', 'models'),
'arguments' => array(
'snapshot' => array('help' => __d('cake_console', 'Generate a snapshot.'))
)
Expand Down
35 changes: 35 additions & 0 deletions lib/Cake/Test/Case/Console/Command/SchemaShellTest.php
Expand Up @@ -362,6 +362,41 @@ public function testGenerateWithPlugins() {
CakePlugin::unload();
}

/**
* test generate with specific models
*
* @return void
*/
public function testGenerateModels() {
App::build(array(
'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
), App::RESET);
CakePlugin::load('TestPlugin');

$this->db->cacheSources = false;
$this->Shell->params = array(
'plugin' => 'TestPlugin',
'connection' => 'test',
'models' => 'TestPluginComment',
'force' => false,
'overwrite' => true
);
$this->Shell->startup();
$this->Shell->Schema->path = TMP . 'tests' . DS;

$this->Shell->generate();
$this->file = new File(TMP . 'tests' . DS . 'schema.php');
$contents = $this->file->read();

$this->assertRegExp('/class TestPluginSchema/', $contents);
$this->assertRegExp('/public \$test_plugin_comments/', $contents);
$this->assertNotRegExp('/public \$authors/', $contents);
$this->assertNotRegExp('/public \$auth_users/', $contents);
$this->assertNotRegExp('/public \$posts/', $contents);
CakePlugin::unload();
}


/**
* Test schema run create with no table args.
*
Expand Down

0 comments on commit 62dee78

Please sign in to comment.