Changeset 423
- Timestamp:
- 10/23/07 10:15:11 (1 year ago)
- Files:
-
- trunk/CHANGELOG.txt (modified) (1 diff)
- trunk/app/installers/database_installer.php (modified) (2 diffs)
- trunk/app/installers/framework_installer.php (modified) (2 diffs)
- trunk/docs/tutorial-es.markdown (modified) (2 diffs)
- trunk/docs/tutorial-fr.markdown (modified) (1 diff)
- trunk/docs/tutorial-ja.markdown (modified) (1 diff)
- trunk/docs/tutorial.markdown (modified) (1 diff)
- trunk/lib/AkActiveRecord/AkHasAndBelongsToMany.php (modified) (1 diff)
- trunk/lib/AkInstaller.php (modified) (3 diffs)
- trunk/lib/utils/generators/model/templates/installer.tpl (modified) (1 diff)
- trunk/lib/utils/generators/model/templates/unit_test.tpl (modified) (2 diffs)
- trunk/lib/utils/generators/scaffold/sintags_templates/installer.tpl (modified) (1 diff)
- trunk/lib/utils/generators/scaffold/sintags_templates/installer_fixture.tpl (modified) (1 diff)
- trunk/lib/utils/generators/scaffold/sintags_templates/model_unit_test.tpl (modified) (1 diff)
- trunk/lib/utils/generators/scaffold/templates/installer.tpl (modified) (1 diff)
- trunk/lib/utils/scripts/test.php (modified) (2 diffs)
- trunk/test/fixtures/app/installers/property_installer.php (modified) (1 diff)
- trunk/test/unit/lib/AkInstaller.php (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/CHANGELOG.txt
r422 r423 1 1 SVN 2 2 ---------------------- 3 * AkInstaller::createTable() will now add created_at and updated_at columns automatically unless you have one of 4 them in your table declaration or set the option 'timestamp' => false 5 6 function up_1(){ 7 $this->createTable('user', 'id, first_name, last_name, email'); // will add created_at, and updated_at 8 } 9 10 to avoid it 11 12 function up_1(){ 13 $this->createTable('user', 'id, first_name, last_name, email', array('timestamp'=>false)); // nothing extra 14 } 15 16 or 17 18 function up_1(){ 19 $this->createTable('user', 'id, first_name, last_name, email, updated_at'); // nothing extra 20 } 21 22 * Simplifying unit test calls for models and core tests. Updated generators to reflect this new way of calling tests. 23 If you stick with the convention of prefixing your test cases with TestCase you will no longer need to call ak__test('testcaseclass') 24 25 Running models test can now be done with simply 26 ./script/test model User 27 28 Core tests can be called without the full path like 29 ./script/test AkActiveRecord 30 3 31 * Rearranged scripts to include as little code as possible in the application space. This should make updates easier. 4 32 trunk/app/installers/database_installer.php
r2 r423 8 8 if($this->_loadDbDesignerDbSchema()){ 9 9 foreach ($this->db_designer_schema as $table=>$columns){ 10 $this->createTable($table, $columns );10 $this->createTable($table, $columns, array('timestamp'=>false)); 11 11 } 12 12 } … … 28 28 foreach ($this->db_designer_schema as $table=>$columns){ 29 29 $this->dropTable($table); 30 $this->createTable($table, $columns );30 $this->createTable($table, $columns, array('timestamp'=>false)); 31 31 } 32 32 } trunk/app/installers/framework_installer.php
r216 r423 10 10 cache_data binary, 11 11 expire datetime' 12 );12 , array('timestamp'=>false)); 13 13 14 14 $this->createTable('sessions', ' … … 16 16 expire datetime, 17 17 value text' 18 );18 , array('timestamp'=>false)); 19 19 } 20 20 trunk/docs/tutorial-es.markdown
r321 r423 192 192 193 193 +--------------+--------------+------+-----+----------------+ 194 | Campo | Tipo| Null | Key | Extra |194 | Field | Type | Null | Key | Extra | 195 195 +--------------+--------------+------+-----+----------------+ 196 196 | id | int(11) | NO | PRI | auto_increment | … … 199 199 | author_id | int(11) | YES | MUL | | 200 200 | published_on | date | YES | | | 201 | updated_at | datetime | YES | | | 202 | created_at | datetime | YES | | | 201 203 +--------------+--------------+------+-----+----------------+ 202 204 203 205 **TABLA AUTHORS** 204 205 +-------+--------------+------+-----+----------------+ 206 | Campo | Tipo | Null | Key | Extra | 207 +-------+--------------+------+-----+----------------+ 208 | id | int(11) | NO | PRI | auto_increment | 209 | name | varchar(255) | YES | | | 210 +-------+--------------+------+-----+----------------+ 206 207 +--------------+--------------+------+-----+----------------+ 208 | Field | Type | Null | Key | Extra | 209 +--------------+--------------+------+-----+----------------+ 210 | id | int(11) | NO | PRI | auto_increment | 211 | name | varchar(255) | YES | | | 212 | updated_at | datetime | YES | | | 213 | created_at | datetime | YES | | | 214 +--------------+--------------+------+-----+----------------+ 211 215 212 216 Modelos, Vistas y Controladores trunk/docs/tutorial-fr.markdown
r321 r423 228 228 | author_id | int(11) | YES | MUL | | 229 229 | published_on | date | YES | | | 230 +--------------+--------------+------+-----+----------------+ 230 | updated_at | datetime | YES | | | 231 | created_at | datetime | YES | | | 232 +--------------+--------------+------+-----+----------------+ 231 233 232 234 **TABLE "AUTHORS"** 233 234 +-------+--------------+------+-----+----------------+ 235 | Field | Type | Null | Key | Extra | 236 +-------+--------------+------+-----+----------------+ 237 | id | int(11) | NO | PRI | auto_increment | 238 | name | varchar(255) | YES | | | 239 +-------+--------------+------+-----+----------------+ 235 236 +--------------+--------------+------+-----+----------------+ 237 | Field | Type | Null | Key | Extra | 238 +--------------+--------------+------+-----+----------------+ 239 | id | int(11) | NO | PRI | auto_increment | 240 | name | varchar(255) | YES | | | 241 | updated_at | datetime | YES | | | 242 | created_at | datetime | YES | | | 243 +--------------+--------------+------+-----+----------------+ 240 244 241 245 trunk/docs/tutorial-ja.markdown
r321 r423 203 203 | author_id | int(11) | YES | MUL | | 204 204 | published_on | date | YES | | | 205 | updated_at | datetime | YES | | | 206 | created_at | datetime | YES | | | 205 207 +--------------+--------------+------+-----+----------------+ 206 208 207 209 **AUTHORS γγΌγγ«** 208 210 209 +-------+--------------+------+-----+----------------+ 210 | Field | Type | Null | Key | Extra | 211 +-------+--------------+------+-----+----------------+ 212 | id | int(11) | NO | PRI | auto_increment | 213 | name | varchar(255) | YES | | | 214 +-------+--------------+------+-----+----------------+ 211 +--------------+--------------+------+-----+----------------+ 212 | Field | Type | Null | Key | Extra | 213 +--------------+--------------+------+-----+----------------+ 214 | id | int(11) | NO | PRI | auto_increment | 215 | name | varchar(255) | YES | | | 216 | updated_at | datetime | YES | | | 217 | created_at | datetime | YES | | | 218 +--------------+--------------+------+-----+----------------+ 215 219 216 220 trunk/docs/tutorial.markdown
r366 r423 201 201 | author_id | int(11) | YES | MUL | | 202 202 | published_on | date | YES | | | 203 | updated_at | datetime | YES | | | 204 | created_at | datetime | YES | | | 203 205 +--------------+--------------+------+-----+----------------+ 204 206 205 207 **AUTHORS TABLE** 206 208 207 +-------+--------------+------+-----+----------------+ 208 | Field | Type | Null | Key | Extra | 209 +-------+--------------+------+-----+----------------+ 210 | id | int(11) | NO | PRI | auto_increment | 211 | name | varchar(255) | YES | | | 212 +-------+--------------+------+-----+----------------+ 209 +--------------+--------------+------+-----+----------------+ 210 | Field | Type | Null | Key | Extra | 211 +--------------+--------------+------+-----+----------------+ 212 | id | int(11) | NO | PRI | auto_increment | 213 | name | varchar(255) | YES | | | 214 | updated_at | datetime | YES | | | 215 | created_at | datetime | YES | | | 216 +--------------+--------------+------+-----+----------------+ 213 217 214 218 trunk/lib/AkActiveRecord/AkHasAndBelongsToMany.php
r420 r423 283 283 require_once(AK_LIB_DIR.DS.'AkDbManager.php'); 284 284 285 AkDbManager::createTable($options['join_table'], "id I AUTO KEY,{$options['foreign_key']} I, {$options['association_foreign_key']} I",array('mysql' => 'TYPE=InnoDB' ),false,285 AkDbManager::createTable($options['join_table'], "id I AUTO KEY,{$options['foreign_key']} I, {$options['association_foreign_key']} I",array('mysql' => 'TYPE=InnoDB','timestamp'=>false),false, 286 286 "{$options['foreign_key']},{$options['association_foreign_key']}"); 287 287 return $this->_hasJoinTable(); trunk/lib/AkInstaller.php
r408 r423 244 244 function createTable($table_name, $column_options = null, $table_options = array()) 245 245 { 246 static $created_tables = array();247 248 if(in_array($table_name, $created_tables)){249 //return false;250 }251 246 if($this->tableExists($table_name)){ 252 247 trigger_error(Ak::t('Table %table_name already exists on the database', array('%table_name'=>$table_name)), E_USER_NOTICE); 253 248 return false; 254 249 } 255 $created_tables[] = $table_name; 250 $this->timestamps = (!isset($table_options['timestamp']) || (isset($table_options['timestamp']) && $table_options['timestamp'])) && 251 (!strstr($column_options, 'created') && !strstr($column_options, 'updated')); 256 252 return $this->_createOrModifyTable($table_name, $column_options, $table_options); 257 253 } … … 390 386 $columns = $this->_setColumnDefaults($columns); 391 387 $this->_ensureColumnNameCompatibility($columns); 388 392 389 $equivalences = array( 393 390 '/ ((limit|max|length) ?= ?)([0-9]+)([ \n\r,]+)/'=> ' (\3) ', … … 419 416 function _setColumnDefaults($columns) 420 417 { 421 $columns = str_replace("\t",' ', $columns); 422 if(is_string($columns)){ 423 if(strstr($columns,"\n")){ 424 $columns = explode("\n",$columns); 425 }elseif(strstr($columns,',')){ 426 $columns = explode(',',$columns); 427 } 428 } 418 $columns = Ak::toArray($columns); 429 419 foreach ((array)$columns as $column){ 430 $column = trim($column, "\n\ r, ");420 $column = trim($column, "\n\t\r, "); 431 421 if(!empty($column)){ 432 422 $single_columns[$column] = $this->_setColumnDefault($column); 433 423 } 424 } 425 if(!empty($this->timestamps) && !isset($single_columns['created_at']) && !isset($single_columns['updated_at'])){ 426 $single_columns['updated_at'] = $this->_setColumnDefault('updated_at'); 427 $single_columns['created_at'] = $this->_setColumnDefault('created_at'); 434 428 } 435 429 return join(",\n", $single_columns); trunk/lib/utils/generators/model/templates/installer.tpl
r262 r423 5 5 function up_1() 6 6 { 7 /** /8 7 $this->createTable('<?php echo AkInflector::tableize($class_name); ?>', " 9 8 id, 10 created_at, 11 updated_at 9 name 12 10 "); 13 /**/14 11 } 15 12 16 13 function down_1() 17 14 { 18 /** /19 15 $this->dropTable('<?php echo AkInflector::tableize($class_name); ?>'); 20 /**/21 16 } 22 23 17 } 24 18 19 25 20 ?> trunk/lib/utils/generators/model/templates/unit_test.tpl
r344 r423 1 1 <?php echo '<?php'?> 2 2 3 // To run this test calling ./script/test unit/app/models/<?php echo $underscored_model_name; ?>4 // More about testing at http://wiki.akelos.org/testing-guide5 3 6 class <?php echo $class_name?>TestCase extends AkUnitTest 4 // Unit test for <?php echo $class_name?>. (Testing docs at http://wiki.akelos.org/testing-guide) 5 // Run this test with the command 6 // ./script/test model <?php echo $class_name?> 7 8 9 class <?php echo $class_name?>TestCase extends AkUnitTest 7 10 { 11 8 12 function test_setup() 9 13 { … … 11 15 } 12 16 13 function test_ <?php echo $class_name?>()17 function test_should_be_added() 14 18 { 15 $this->assertTrue(false,'Unit test for <?php echo $class_name?> not implemented'); 19 // An instance of <?php echo $class_name?> model is available at 20 // $this-><?php echo $class_name; ?> 21 22 $this->assertTrue(false); 16 23 } 17 24 } 18 25 26 19 27 ?> trunk/lib/utils/generators/scaffold/sintags_templates/installer.tpl
r265 r423 19 19 $this->createTable('<?php echo $plural_name?>', " 20 20 id, 21 name, 22 description, 23 created_at, 24 updated_at 21 name 25 22 "); 26 23 } trunk/lib/utils/generators/scaffold/sintags_templates/installer_fixture.tpl
r265 r423 1 1 <?php echo '<?php'?> 2 2 3 require_once(AK_BASE_DIR.DS.'app'.DS.'installers'.DS.substr(strrchr(__FILE__, DS), 1)); 3 require_once(AK_BASE_DIR.DS.'app'.DS.'installers'.<?php 4 echo !empty($module_preffix) ? "DS.'".trim($module_preffix,DS)."'." : '' 5 ?>DS.substr(strrchr(__FILE__, DS), 1)); 4 6 5 7 ?> trunk/lib/utils/generators/scaffold/sintags_templates/model_unit_test.tpl
r265 r423 1 1 <?php echo '<?php'?> 2 2 3 defined('AK_TEST_DATABASE_ON') ? null : define('AK_TEST_DATABASE_ON', true);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');8 3 9 class <?php echo $model_name?>Test extends AkUnitTest 4 // Unit test for <?php echo $plural_name?>. (Testing docs at http://wiki.akelos.org/testing-guide) 5 // Run this test with the command 6 // ./script/test model <?php echo $model_name?> 7 8 9 class <?php echo $model_name?>TestCase extends AkUnitTest 10 10 { 11 <?php 12 echo !empty($module_preffix) ? ' var $module = \''.trim($module_preffix,DS).'\';' : '' 13 ?> 14 11 15 function test_setup() 12 16 { 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(); 17 $this->installAndIncludeModels('<?php echo $model_name?>'); 17 18 } 18 19 19 function test_ <?php echo $model_name?>()20 function test_should_be_added() 20 21 { 21 $this->assertTrue(false,'Unit test for <?php echo $model_name?> not implemented'); 22 // An instance of <?php echo $model_name?> model is available at 23 // $this-><?php echo $model_name; ?> 24 25 $this->assertTrue(false); 22 26 } 23 27 } 24 28 25 29 26 ak_test('<?php echo $model_name?>Test',true);27 28 30 ?> trunk/lib/utils/generators/scaffold/templates/installer.tpl
r155 r423 19 19 $this->createTable('<?php echo $plural_name?>', " 20 20 id, 21 name, 22 description, 23 created_at, 24 updated_at 21 name 25 22 "); 26 23 } trunk/lib/utils/scripts/test.php
r421 r423 1 2 1 <?php 3 2 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ … … 18 17 */ 19 18 19 if(preg_match('/^model/i', $argv[0])){ 20 array_shift($argv); 21 foreach ($argv as $k=>$v){ 22 $argv[$k] = 'unit/app/models/'.AkInflector::underscore($v); 23 } 24 }elseif(preg_match('/^Ak[a-zA-Z]+/', $argv[0]) && is_dir(AK_BASE_DIR.DS.'test'.DS.'unit'.DS.'lib')){ 25 foreach ($argv as $k=>$v){ 26 $argv[$k] = 'unit/lib/'.$v; 27 } 28 } 20 29 21 30 $____skip_tests = array('Simple','Unit','Web','AkWeb'); trunk/test/fixtures/app/installers/property_installer.php
r2 r423 12 12 landlord_id integer, 13 13 price integer, 14 location string limit=200' 15 );14 location string limit=200', 15 array('timestamp'=>false)); 16 16 } 17 17 trunk/test/unit/lib/AkInstaller.php
r323 r423 136 136 description text, 137 137 parent_id integer(11) not null default '0' 138 " );138 ", array('timestamp'=>false)); 139 139 140 140 … … 142 142 category_id integer(11) not null, 143 143 page_id integer(11) not null 144 " );144 ", array('timestamp'=>false)); 145 145 146 146 $this->Installer->createTable('test_nice_urls', " … … 149 149 context_id integer(11) not null, 150 150 context string(255) not null default 'page' 151 " );151 ", array('timestamp'=>false)); 152 152 153 153
