Changeset 318
- Timestamp:
- 08/23/07 13:23:14 (1 year ago)
- Files:
-
- trunk/lib/AkInflector.php (modified) (1 diff)
- trunk/script/generators/model/model_generator.php (modified) (3 diffs)
- trunk/script/generators/scaffold/templates/model_unit_test.tpl (modified) (3 diffs)
- trunk/test/unit/lib/AkInflector.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/lib/AkInflector.php
r285 r318 507 507 } 508 508 509 function is_singular($singular) 510 { 511 return AkInflector::singularize(AkInflector::pluralize($singular)) == $singular; 512 } 513 514 function is_plural($plural) 515 { 516 return AkInflector::pluralize(AkInflector::singularize($plural)) == $plural; 517 } 509 518 510 519 } trunk/script/generators/model/model_generator.php
r266 r318 30 30 $this->installer_path = 'app'.DS.'installers'.DS.$this->underscored_model_name.'_installer.php'; 31 31 } 32 32 33 33 function hasCollisions() 34 34 { 35 35 $this->_preloadPaths(); 36 36 37 37 $this->collisions = array(); 38 39 if(AkInflector::is_plural($this->class_name)){ 40 $this->collisions[] = Ak::t('%class_name should be a singular noun',array('%class_name'=>$this->class_name)); 41 } 38 42 39 43 $files = array( … … 55 59 { 56 60 $this->_preloadPaths(); 57 61 58 62 $this->class_name = AkInflector::camelize($this->class_name); 59 63 … … 68 72 $this->save($file_path, $this->render($template)); 69 73 } 70 74 71 75 $installer_path = AK_APP_DIR.DS.'installers'.DS.$this->underscored_model_name.'_installer.php'; 72 76 if(!file_exists($installer_path)){ 73 77 $this->save($installer_path, $this->render('installer')); 74 78 } 75 79 76 80 $unit_test_runner = AK_TEST_DIR.DS.'unit.php'; 77 81 if(!file_exists($unit_test_runner)){ 78 82 Ak::file_put_contents($unit_test_runner, file_get_contents(AK_FRAMEWORK_DIR.DS.'test'.DS.'app.php')); 79 83 } 80 84 81 85 } 82 86 83 87 function cast() 84 88 { trunk/script/generators/scaffold/templates/model_unit_test.tpl
r217 r318 3 3 defined('AK_TEST_DATABASE_ON') ? null : define('AK_TEST_DATABASE_ON', true); 4 4 require_once(dirname(__FILE__).'/../../../fixtures/config/config.php'); 5 require_once(AK_LIB_DIR.DS.'AkActiveRecord.php'); 6 require_once(AK_APP_DIR.DS.'shared_model.php'); 7 require_once(AK_MODELS_DIR.DS.'<?php echo $singular_name?>.php'); 5 6 // You can execute this test by running 7 // ./script/test app/models/<?php echo AkInflector::underscore($class_name)?>.php 8 8 9 9 class <?php echo $model_name?>Test extends AkUnitTest … … 11 11 function test_setup() 12 12 { 13 require_once(AK_APP_DIR.DS.'installers'.DS.'<?php echo $singular_name?>_installer.php'); 14 $installer = new <?php echo $model_name?>Installer(); 15 $installer->uninstall(); 16 $installer->install(); 13 $this->installAndIncludeModels('<?php echo $model_name?>'); 17 14 } 18 15 19 16 function test_<?php echo $model_name?>() 20 17 { … … 23 20 } 24 21 25 26 22 ak_test('<?php echo $model_name?>Test',true); 27 23 trunk/test/unit/lib/AkInflector.php
r282 r318 285 285 $this->assertEqual(AkInflector::singularize('camiones'), 'camión'); 286 286 } 287 288 function test_should_detect_singulars() 289 { 290 foreach (array_keys($this->SingularToPlural) as $singular){ 291 $this->assertTrue(AkInflector::is_singular($singular), $singular.' is not detected as singular'); 292 } 293 } 294 295 function test_should_detect_plurals() 296 { 297 foreach (array_values($this->SingularToPlural) as $plural){ 298 $this->assertTrue(AkInflector::is_plural($plural), $plural.' is not detected as plural'); 299 } 300 } 287 301 288 302 }
