From 035f727686883d6201207fff43e22c5d7c99cb85 Mon Sep 17 00:00:00 2001 From: ADmad Date: Sun, 30 Sep 2012 13:08:57 +0530 Subject: [PATCH] Replace Model::read() with Model::find('first') in baked controller Removed references to Ajax and Javascript helpers --- .../Console/Command/Task/ControllerTask.php | 2 +- .../default/actions/controller_actions.ctp | 12 +++++------ .../Command/Task/ControllerTaskTest.php | 21 ++++++++++--------- 3 files changed, 18 insertions(+), 17 deletions(-) diff --git a/lib/Cake/Console/Command/Task/ControllerTask.php b/lib/Cake/Console/Command/Task/ControllerTask.php index 4da40184ec1..11ba8a61a36 100644 --- a/lib/Cake/Console/Command/Task/ControllerTask.php +++ b/lib/Cake/Console/Command/Task/ControllerTask.php @@ -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'") ); } diff --git a/lib/Cake/Console/Templates/default/actions/controller_actions.ctp b/lib/Cake/Console/Templates/default/actions/controller_actions.ctp index 21b6ab8ea31..88f20c6f0c2 100644 --- a/lib/Cake/Console/Templates/default/actions/controller_actions.ctp +++ b/lib/Cake/Console/Templates/default/actions/controller_actions.ctp @@ -36,11 +36,11 @@ * @return void */ public function view($id = null) { - $this->->id = $id; - if (!$this->->exists()) { + if (!$this->->exists($id)) { throw new NotFoundException(__('Invalid ')); } - $this->set('', $this->->read(null, $id)); + $options = array('conditions' => array('.' . $this->->primaryKey => $id)); + $this->set('', $this->->find('first', $options)); } @@ -91,8 +91,7 @@ * @return void */ public function edit($id = null) { - $this->->id = $id; - if (!$this->->exists()) { + if (!$this->->exists($id)) { throw new NotFoundException(__('Invalid ')); } if ($this->request->is('post') || $this->request->is('put')) { @@ -109,7 +108,8 @@ } } else { - $this->request->data = $this->->read(null, $id); + $options = array('conditions' => array('.' . $this->->primaryKey => $id)); + $this->request->data = $this->->find('first', $options); } 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); } @@ -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); } @@ -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); } @@ -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)); @@ -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); @@ -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); @@ -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);