Skip to content
This repository
Browse code

adding models for schema generate

  • Loading branch information...
commit 62dee78ca5ab69356a026d89e025c0b2d762886b 1 parent 5e0e850
Mark authored August 08, 2012
10  lib/Cake/Console/Command/SchemaShell.php
@@ -127,7 +127,9 @@ public function generate() {
127 127
 		$this->out(__d('cake_console', 'Generating Schema...'));
128 128
 		$options = array();
129 129
 		if ($this->params['force']) {
130  
-			$options = array('models' => false);
  130
+			$options['models'] = false;
  131
+		} elseif (!empty($this->params['models'])) {
  132
+			$options['models'] = String::tokenize($this->params['models']);
131 133
 		}
132 134
 
133 135
 		$snapshot = false;
@@ -464,6 +466,10 @@ public function getOptionParser() {
464 466
 			'short' => 's',
465 467
 			'help' => __d('cake_console', 'Snapshot number to use/make.')
466 468
 		);
  469
+		$models = array(
  470
+			'short' => 'm',
  471
+			'help' => __d('cake_console', 'Specify models as comma separated list.'),
  472
+		);
467 473
 		$dry = array(
468 474
 			'help' => __d('cake_console', 'Perform a dry run on create and update commands. Queries will be output instead of run.'),
469 475
 			'boolean' => true
@@ -489,7 +495,7 @@ public function getOptionParser() {
489 495
 		))->addSubcommand('generate', array(
490 496
 			'help' => __d('cake_console', 'Reads from --connection and writes to --path. Generate snapshots with -s'),
491 497
 			'parser' => array(
492  
-				'options' => compact('plugin', 'path', 'file', 'name', 'connection', 'snapshot', 'force'),
  498
+				'options' => compact('plugin', 'path', 'file', 'name', 'connection', 'snapshot', 'force', 'models'),
493 499
 				'arguments' => array(
494 500
 					'snapshot' => array('help' => __d('cake_console', 'Generate a snapshot.'))
495 501
 				)
35  lib/Cake/Test/Case/Console/Command/SchemaShellTest.php
@@ -363,6 +363,41 @@ public function testGenerateWithPlugins() {
363 363
 	}
364 364
 
365 365
 /**
  366
+ * test generate with specific models
  367
+ *
  368
+ * @return void
  369
+ */
  370
+	public function testGenerateModels() {
  371
+		App::build(array(
  372
+			'Plugin' => array(CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS)
  373
+		), App::RESET);
  374
+		CakePlugin::load('TestPlugin');
  375
+
  376
+		$this->db->cacheSources = false;
  377
+		$this->Shell->params = array(
  378
+			'plugin' => 'TestPlugin',
  379
+			'connection' => 'test',
  380
+			'models' => 'TestPluginComment',
  381
+			'force' => false,
  382
+			'overwrite' => true
  383
+		);
  384
+		$this->Shell->startup();
  385
+		$this->Shell->Schema->path = TMP . 'tests' . DS;
  386
+
  387
+		$this->Shell->generate();
  388
+		$this->file = new File(TMP . 'tests' . DS . 'schema.php');
  389
+		$contents = $this->file->read();
  390
+
  391
+		$this->assertRegExp('/class TestPluginSchema/', $contents);
  392
+		$this->assertRegExp('/public \$test_plugin_comments/', $contents);
  393
+		$this->assertNotRegExp('/public \$authors/', $contents);
  394
+		$this->assertNotRegExp('/public \$auth_users/', $contents);
  395
+		$this->assertNotRegExp('/public \$posts/', $contents);
  396
+		CakePlugin::unload();
  397
+	}
  398
+
  399
+
  400
+/**
366 401
  * Test schema run create with no table args.
367 402
  *
368 403
  * @return void

0 notes on commit 62dee78

Please sign in to comment.
Something went wrong with that request. Please try again.