Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixing how scaffold arg works, now generates scaffolds.

Making admin arg only make admin methods and new both arg make both admin and non admin methods.
Adding test cases.
Adding new line to template.
  • Loading branch information...
commit 9092b25004cf975e1d6ad49e83202716a492be36 1 parent 8ae8a08
@markstory markstory authored
View
39 cake/console/libs/tasks/controller.php
@@ -81,19 +81,20 @@ function execute() {
$controller = Inflector::camelize($this->args[0]);
$actions = null;
if (isset($this->args[1]) && $this->args[1] == 'scaffold') {
- $this->out(__('Baking scaffold for ', true) . $controller);
- $actions = $this->bakeActions($controller);
- } else {
$actions = 'scaffold';
+ } else {
+ $this->out(__('Baking basic crud methods for ', true) . $controller);
+ $actions = $this->bakeActions($controller);
}
- if ((isset($this->args[1]) && $this->args[1] == 'admin') || (isset($this->args[2]) && $this->args[2] == 'admin')) {
- if ($admin = $this->Project->getAdmin()) {
+ if (isset($this->args[1]) && ($this->args[1] == 'admin' || $this->args[1] == 'both')) {
+ $admin = $this->Project->getAdmin();
+ if ($admin) {
$this->out('Adding ' . Configure::read('Routing.admin') .' methods');
- if ($actions == 'scaffold') {
- $actions = $this->bakeActions($controller, $admin);
- } else {
- $actions .= $this->bakeActions($controller, $admin);
- }
+ $adminActions = $this->bakeActions($controller, $admin);
+ }
+ $actions .= "\n" . $adminActions;
+ if ($this->args[1] == 'admin') {
+ $actions = $adminActions;
}
}
if ($this->bake($controller, $actions)) {
@@ -454,19 +455,19 @@ function help() {
$this->out('Commands:');
$this->out('');
$this->out("controller <name>");
- $this->out("\tbakes controller with var \$scaffold");
- $this->out('');
- $this->out("controller <name> scaffold");
- $this->out("\tbakes controller with scaffold actions.");
+ $this->out("\tbakes controller with basic crud actions");
$this->out("\t(index, view, add, edit, delete)");
$this->out('');
- $this->out("controller <name> scaffold admin");
- $this->out("\tbakes a controller with scaffold actions for both public");
- $this->out("\tand Configure::read('Routing.admin')");
+ $this->out("controller <name> scaffold");
+ $this->out("\tbakes controller with var \$scaffold.");
$this->out('');
$this->out("controller <name> admin");
- $this->out("\tbakes a controller with scaffold actions only for");
- $this->out("\tConfigure::read('Routing.admin')");
+ $this->out("\tbakes a controller with basic crud actions for");
+ $this->out("\tConfigure::read('Routing.admin') methods.");
+ $this->out('');
+ $this->out("controller <name> both");
+ $this->out("\tbakes a controller with basic crud actions for");
+ $this->out("\tConfigure::read('Routing.admin') and non admin methods.");
$this->out('');
$this->out("controller all");
$this->out("\tbakes all controllers with CRUD methods.");
View
1  cake/console/templates/default/classes/controller.ctp
@@ -53,5 +53,6 @@ endif;
echo $actions;
endif; ?>
+
}
<?php echo "?>"; ?>
View
59 cake/tests/cases/console/libs/tasks/controller.test.php
@@ -445,30 +445,77 @@ function testExecuteWithScaffoldParam() {
$filename = '/my/path/articles_controller.php';
$this->Task->expectAt(0, 'createFile', array(
- $filename, new NoPatternExpectation('/admin_index/')
+ $filename, new PatternExpectation('/var \$scaffold/')
));
$this->Task->execute();
}
/**
- * test that `cake bake controller foo scaffold admin` works
+ * test that `cake bake controller foos` works.
*
* @return void
**/
- function testExecuteWithAdminScaffoldParams() {
+ function testExecuteWithController() {
$skip = $this->skipIf(!defined('ARTICLE_MODEL_CREATED'),
- 'Execute with scaffold admin param requires no Article, Tag or Comment model to be defined. %s');
+ 'Execute with scaffold param requires no Article, Tag or Comment model to be defined. %s');
+ if ($skip) {
+ return;
+ }
+ $this->Task->connection = 'test_suite';
+ $this->Task->path = '/my/path/';
+ $this->Task->args = array('Articles');
+
+ $filename = '/my/path/articles_controller.php';
+ $this->Task->expectAt(0, 'createFile', array(
+ $filename, new NoPatternExpectation('/admin/')
+ ));
+
+ $this->Task->execute();
+ }
+
+/**
+ * test that `cake bake controller foos both` works.
+ *
+ * @return void
+ **/
+ function testExecuteWithControllerAndBoth() {
+ $skip = $this->skipIf(!defined('ARTICLE_MODEL_CREATED'),
+ 'Execute with scaffold param requires no Article, Tag or Comment model to be defined. %s');
+ if ($skip) {
+ return;
+ }
+ $this->Task->Project->setReturnValue('getAdmin', 'admin_');
+ $this->Task->connection = 'test_suite';
+ $this->Task->path = '/my/path/';
+ $this->Task->args = array('Articles', 'both');
+
+ $filename = '/my/path/articles_controller.php';
+ $this->Task->expectAt(0, 'createFile', array(
+ $filename, new PatternExpectation('/admin_index/')
+ ));
+
+ $this->Task->execute();
+ }
+
+/**
+ * test that `cake bake controller foos admin` works.
+ *
+ * @return void
+ **/
+ function testExecuteWithControllerAndAdmin() {
+ $skip = $this->skipIf(!defined('ARTICLE_MODEL_CREATED'),
+ 'Execute with scaffold param requires no Article, Tag or Comment model to be defined. %s');
if ($skip) {
return;
}
$this->Task->Project->setReturnValue('getAdmin', 'admin_');
$this->Task->connection = 'test_suite';
$this->Task->path = '/my/path/';
- $this->Task->args = array('Articles', 'scaffold', 'admin');
+ $this->Task->args = array('Articles', 'admin');
$filename = '/my/path/articles_controller.php';
- $this->Task->expect('createFile', array(
+ $this->Task->expectAt(0, 'createFile', array(
$filename, new PatternExpectation('/admin_index/')
));
Please sign in to comment.
Something went wrong with that request. Please try again.