Skip to content

Commit

Permalink
Replace Model::read() with Model::find('first') in baked controller
Browse files Browse the repository at this point in the history
Removed references to Ajax and Javascript helpers
  • Loading branch information
ADmad committed Sep 30, 2012
1 parent 59e948f commit 035f727
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lib/Cake/Console/Command/Task/ControllerTask.php
Expand Up @@ -349,7 +349,7 @@ public function bakeTest($className) {
public function doHelpers() {
return $this->_doPropertyChoices(
__d('cake_console', "Would you like this controller to use other helpers\nbesides HtmlHelper and FormHelper?"),
__d('cake_console', "Please provide a comma separated list of the other\nhelper names you'd like to use.\nExample: 'Ajax, Javascript, Time'")
__d('cake_console', "Please provide a comma separated list of the other\nhelper names you'd like to use.\nExample: 'Text, Js, Time'")
);
}

Expand Down
Expand Up @@ -36,11 +36,11 @@
* @return void
*/
public function <?php echo $admin ?>view($id = null) {
$this-><?php echo $currentModelName; ?>->id = $id;
if (!$this-><?php echo $currentModelName; ?>->exists()) {
if (!$this-><?php echo $currentModelName; ?>->exists($id)) {
throw new NotFoundException(__('Invalid <?php echo strtolower($singularHumanName); ?>'));
}
$this->set('<?php echo $singularName; ?>', $this-><?php echo $currentModelName; ?>->read(null, $id));
$options = array('conditions' => array('<?php echo $currentModelName; ?>.' . $this-><?php echo $currentModelName; ?>->primaryKey => $id));
$this->set('<?php echo $singularName; ?>', $this-><?php echo $currentModelName; ?>->find('first', $options));
}

<?php $compact = array(); ?>
Expand Down Expand Up @@ -91,8 +91,7 @@
* @return void
*/
public function <?php echo $admin; ?>edit($id = null) {
$this-><?php echo $currentModelName; ?>->id = $id;
if (!$this-><?php echo $currentModelName; ?>->exists()) {
if (!$this-><?php echo $currentModelName; ?>->exists($id)) {
throw new NotFoundException(__('Invalid <?php echo strtolower($singularHumanName); ?>'));
}
if ($this->request->is('post') || $this->request->is('put')) {
Expand All @@ -109,7 +108,8 @@
<?php endif; ?>
}
} else {
$this->request->data = $this-><?php echo $currentModelName; ?>->read(null, $id);
$options = array('conditions' => array('<?php echo $currentModelName; ?>.' . $this-><?php echo $currentModelName; ?>->primaryKey => $id));
$this->request->data = $this-><?php echo $currentModelName; ?>->find('first', $options);
}
<?php
foreach (array('belongsTo', 'hasAndBelongsToMany') as $assoc):
Expand Down
21 changes: 11 additions & 10 deletions lib/Cake/Test/Case/Console/Command/Task/ControllerTaskTest.php
Expand Up @@ -191,9 +191,9 @@ public function testDoHelpersNo() {
*/
public function testDoHelpersTrailingSpace() {
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue(' Javascript, Ajax, CustomOne '));
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue(' Text, Number, CustomOne '));
$result = $this->Task->doHelpers();
$expected = array('Javascript', 'Ajax', 'CustomOne');
$expected = array('Text', 'Number', 'CustomOne');
$this->assertEquals($expected, $result);
}

Expand All @@ -204,9 +204,9 @@ public function testDoHelpersTrailingSpace() {
*/
public function testDoHelpersTrailingCommas() {
$this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y'));
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue(' Javascript, Ajax, CustomOne, , '));
$this->Task->expects($this->at(1))->method('in')->will($this->returnValue(' Text, Number, CustomOne, , '));
$result = $this->Task->doHelpers();
$expected = array('Javascript', 'Ajax', 'CustomOne');
$expected = array('Text', 'Number', 'CustomOne');
$this->assertEquals($expected, $result);
}

Expand Down Expand Up @@ -257,11 +257,11 @@ public function testDoComponentsTrailingCommas() {
public function testConfirmController() {
$controller = 'Posts';
$scaffold = false;
$helpers = array('Ajax', 'Time');
$helpers = array('Js', 'Time');
$components = array('Acl', 'Auth');

$this->Task->expects($this->at(4))->method('out')->with("Controller Name:\n\t$controller");
$this->Task->expects($this->at(5))->method('out')->with("Helpers:\n\tAjax, Time");
$this->Task->expects($this->at(5))->method('out')->with("Helpers:\n\tJs, Time");
$this->Task->expects($this->at(6))->method('out')->with("Components:\n\tAcl, Auth");
$this->Task->confirmController($controller, $scaffold, $helpers, $components);
}
Expand All @@ -272,7 +272,7 @@ public function testConfirmController() {
* @return void
*/
public function testBake() {
$helpers = array('Ajax', 'Time');
$helpers = array('Js', 'Time');
$components = array('Acl', 'Auth');
$this->Task->expects($this->any())->method('createFile')->will($this->returnValue(true));

Expand All @@ -282,7 +282,7 @@ public function testBake() {
$this->assertContains(' * @property AuthComponent $Auth', $result);
$this->assertContains('class ArticlesController extends AppController', $result);
$this->assertContains("public \$components = array('Acl', 'Auth')", $result);
$this->assertContains("public \$helpers = array('Ajax', 'Time')", $result);
$this->assertContains("public \$helpers = array('Js', 'Time')", $result);
$this->assertContains("--actions--", $result);

$result = $this->Task->bake('Articles', 'scaffold', $helpers, $components);
Expand Down Expand Up @@ -350,7 +350,8 @@ public function testBakeActionsUsingSessions() {

$this->assertContains('function view($id = null)', $result);
$this->assertContains("throw new NotFoundException(__('Invalid bake article'));", $result);
$this->assertContains("\$this->set('bakeArticle', \$this->BakeArticle->read(null, \$id)", $result);
$this->assertContains("\$options = array('conditions' => array('BakeArticle.' . \$this->BakeArticle->primaryKey => \$id));", $result);
$this->assertContains("\$this->set('bakeArticle', \$this->BakeArticle->find('first', \$options));", $result);

$this->assertContains('function add()', $result);
$this->assertContains("if (\$this->request->is('post'))", $result);
Expand Down Expand Up @@ -389,7 +390,7 @@ public function testBakeActionsWithNoSessions() {

$this->assertContains('function view($id = null)', $result);
$this->assertContains("throw new NotFoundException(__('Invalid bake article'));", $result);
$this->assertContains("\$this->set('bakeArticle', \$this->BakeArticle->read(null, \$id)", $result);
$this->assertContains("\$this->set('bakeArticle', \$this->BakeArticle->find('first', \$options));", $result);

$this->assertContains('function add()', $result);
$this->assertContains("if (\$this->request->is('post'))", $result);
Expand Down

0 comments on commit 035f727

Please sign in to comment.