Changeset 423

Show
Ignore:
Timestamp:
10/23/07 10:15:11 (1 year ago)
Author:
bermiferrer
Message:
  • Simplifying unit test calls for models and core tests. Updated generators to reflect this new way of calling tests.

If you stick with the convention of prefixing your test cases with TestCase? you will no longer need to call ak_test('testcaseclass')

Running models test can now be done with simply

./script/test model User


Core tests can be called without the full path like

./script/test AkActiveRecord
  • Adding default timestamp fields on newly created tables.

AkInstaller::createTable() will now add created_at and updated_at columns automatically unless you have one of
them in your table declaration or set the option 'timestamp' => false

function up_1(){
  $this->createTable('user', 'id, first_name, last_name, email'); // will add created_at, and updated_at
}

to avoid it

function up_1(){
    $this->createTable('user', 'id, first_name, last_name, email', array('timestamp'=>false)); // nothing extra
}   

or

function up_1(){
    $this->createTable('user', 'id, first_name, last_name, email, updated_at'); // nothing extra
}   
  • Fixed bug on AkInstaller::createTable() where it was not possible to separate columns using both newlines and commas.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/CHANGELOG.txt

    r422 r423  
    11SVN 
    22---------------------- 
     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 
    331* Rearranged scripts to include as little code as possible in the application space. This should make updates easier. 
    432 
  • trunk/app/installers/database_installer.php

    r2 r423  
    88        if($this->_loadDbDesignerDbSchema()){ 
    99            foreach ($this->db_designer_schema as $table=>$columns){ 
    10                 $this->createTable($table, $columns); 
     10                $this->createTable($table, $columns, array('timestamp'=>false)); 
    1111            } 
    1212        } 
     
    2828            foreach ($this->db_designer_schema as $table=>$columns){ 
    2929                $this->dropTable($table); 
    30                 $this->createTable($table, $columns); 
     30                $this->createTable($table, $columns, array('timestamp'=>false)); 
    3131            } 
    3232        } 
  • trunk/app/installers/framework_installer.php

    r216 r423  
    1010        cache_data binary, 
    1111        expire datetime' 
    12         ); 
     12        , array('timestamp'=>false)); 
    1313                 
    1414        $this->createTable('sessions', ' 
     
    1616        expire datetime, 
    1717        value text' 
    18         ); 
     18        , array('timestamp'=>false)); 
    1919    } 
    2020 
  • trunk/docs/tutorial-es.markdown

    r321 r423  
    192192 
    193193    +--------------+--------------+------+-----+----------------+ 
    194     | Campo        | Tipo         | Null | Key | Extra          | 
     194    | Field        | Type         | Null | Key | Extra          | 
    195195    +--------------+--------------+------+-----+----------------+ 
    196196    | id           | int(11)      | NO   | PRI | auto_increment | 
     
    199199    | author_id    | int(11)      | YES  | MUL |                | 
    200200    | published_on | date         | YES  |     |                | 
     201    | updated_at   | datetime     | YES  |     |                | 
     202    | created_at   | datetime     | YES  |     |                | 
    201203    +--------------+--------------+------+-----+----------------+  
    202204 
    203205**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    +--------------+--------------+------+-----+----------------+ 
    211215 
    212216Modelos, Vistas y Controladores 
  • trunk/docs/tutorial-fr.markdown

    r321 r423  
    228228    | author_id    | int(11)      | YES  | MUL |                | 
    229229    | published_on | date         | YES  |     |                | 
    230     +--------------+--------------+------+-----+----------------+  
     230    | updated_at   | datetime     | YES  |     |                | 
     231    | created_at   | datetime     | YES  |     |                | 
     232    +--------------+--------------+------+-----+----------------+ 
    231233 
    232234**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    +--------------+--------------+------+-----+----------------+ 
    240244 
    241245 
  • trunk/docs/tutorial-ja.markdown

    r321 r423  
    203203    | author_id    | int(11)      | YES  | MUL |                | 
    204204    | published_on | date         | YES  |     |                | 
     205    | updated_at   | datetime     | YES  |     |                | 
     206    | created_at   | datetime     | YES  |     |                | 
    205207    +--------------+--------------+------+-----+----------------+  
    206208 
    207209**AUTHORS テーブル** 
    208210                        
    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    +--------------+--------------+------+-----+----------------+ 
    215219 
    216220 
  • trunk/docs/tutorial.markdown

    r366 r423  
    201201    | author_id    | int(11)      | YES  | MUL |                | 
    202202    | published_on | date         | YES  |     |                | 
     203    | updated_at   | datetime     | YES  |     |                | 
     204    | created_at   | datetime     | YES  |     |                | 
    203205    +--------------+--------------+------+-----+----------------+  
    204206 
    205207**AUTHORS TABLE** 
    206208                        
    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    +--------------+--------------+------+-----+----------------+ 
    213217 
    214218 
  • trunk/lib/AkActiveRecord/AkHasAndBelongsToMany.php

    r420 r423  
    283283        require_once(AK_LIB_DIR.DS.'AkDbManager.php'); 
    284284 
    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, 
    286286        "{$options['foreign_key']},{$options['association_foreign_key']}"); 
    287287        return $this->_hasJoinTable(); 
  • trunk/lib/AkInstaller.php

    r408 r423  
    244244    function createTable($table_name, $column_options = null, $table_options = array()) 
    245245    { 
    246         static $created_tables = array(); 
    247          
    248         if(in_array($table_name, $created_tables)){ 
    249             //return false; 
    250         } 
    251246        if($this->tableExists($table_name)){ 
    252247            trigger_error(Ak::t('Table %table_name already exists on the database', array('%table_name'=>$table_name)), E_USER_NOTICE); 
    253248            return false; 
    254249        } 
    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')); 
    256252        return $this->_createOrModifyTable($table_name, $column_options, $table_options); 
    257253    } 
     
    390386        $columns = $this->_setColumnDefaults($columns); 
    391387        $this->_ensureColumnNameCompatibility($columns); 
     388 
    392389        $equivalences = array( 
    393390        '/ ((limit|max|length) ?= ?)([0-9]+)([ \n\r,]+)/'=> ' (\3) ', 
     
    419416    function _setColumnDefaults($columns) 
    420417    { 
    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); 
    429419        foreach ((array)$columns as $column){ 
    430             $column = trim($column, "\n\r, "); 
     420            $column = trim($column, "\n\t\r, "); 
    431421            if(!empty($column)){ 
    432422                $single_columns[$column] = $this->_setColumnDefault($column); 
    433423            } 
     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'); 
    434428        } 
    435429        return join(",\n", $single_columns); 
  • trunk/lib/utils/generators/model/templates/installer.tpl

    r262 r423  
    55    function up_1() 
    66    { 
    7         /** / 
    87        $this->createTable('<?php  echo AkInflector::tableize($class_name); ?>', " 
    98          id, 
    10           created_at, 
    11           updated_at 
     9          name 
    1210        "); 
    13         /**/ 
    1411    } 
    1512     
    1613    function down_1() 
    1714    { 
    18         /** / 
    1915        $this->dropTable('<?php  echo AkInflector::tableize($class_name); ?>'); 
    20         /**/ 
    2116    } 
    22      
    2317} 
    2418 
     19 
    2520?> 
  • trunk/lib/utils/generators/model/templates/unit_test.tpl

    r344 r423  
    11<?php  echo '<?php'?> 
    22 
    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-guide 
    53 
    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 
     9class <?php  echo $class_name?>TestCase extends  AkUnitTest 
    710{ 
     11 
    812    function test_setup() 
    913    { 
     
    1115    } 
    1216     
    13     function test_<?php  echo $class_name?>() 
     17    function test_should_be_added() 
    1418    { 
    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); 
    1623    } 
    1724} 
    1825 
     26 
    1927?> 
  • trunk/lib/utils/generators/scaffold/sintags_templates/installer.tpl

    r265 r423  
    1919        $this->createTable('<?php  echo $plural_name?>', " 
    2020          id, 
    21           name, 
    22           description, 
    23           created_at, 
    24           updated_at 
     21          name 
    2522        ");   
    2623    } 
  • trunk/lib/utils/generators/scaffold/sintags_templates/installer_fixture.tpl

    r265 r423  
    11<?php  echo '<?php'?> 
    22 
    3 require_once(AK_BASE_DIR.DS.'app'.DS.'installers'.DS.substr(strrchr(__FILE__, DS), 1)); 
     3require_once(AK_BASE_DIR.DS.'app'.DS.'installers'.<?php  
     4echo !empty($module_preffix) ? "DS.'".trim($module_preffix,DS)."'." : '' 
     5?>DS.substr(strrchr(__FILE__, DS), 1)); 
    46 
    57?> 
  • trunk/lib/utils/generators/scaffold/sintags_templates/model_unit_test.tpl

    r265 r423  
    11<?php  echo '<?php'?> 
    22 
    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'); 
    83 
    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 
     9class <?php  echo $model_name?>TestCase extends  AkUnitTest 
    1010{ 
     11<?php  
     12echo !empty($module_preffix) ? '    var $module = \''.trim($module_preffix,DS).'\';' : '' 
     13?> 
     14 
    1115    function test_setup() 
    1216    { 
    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?>'); 
    1718    } 
    1819     
    19     function test_<?php  echo $model_name?>() 
     20    function test_should_be_added() 
    2021    { 
    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); 
    2226    } 
    2327} 
    2428 
    2529 
    26 ak_test('<?php  echo $model_name?>Test',true); 
    27  
    2830?> 
  • trunk/lib/utils/generators/scaffold/templates/installer.tpl

    r155 r423  
    1919        $this->createTable('<?php  echo $plural_name?>', " 
    2020          id, 
    21           name, 
    22           description, 
    23           created_at, 
    24           updated_at 
     21          name 
    2522        ");   
    2623    } 
  • trunk/lib/utils/scripts/test.php

    r421 r423  
    1  
    21<?php 
    32/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */ 
     
    1817 */ 
    1918 
     19if(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} 
    2029 
    2130$____skip_tests = array('Simple','Unit','Web','AkWeb'); 
  • trunk/test/fixtures/app/installers/property_installer.php

    r2 r423  
    1212        landlord_id integer, 
    1313        price integer, 
    14         location string limit=200' 
    15         ); 
     14        location string limit=200', 
     15        array('timestamp'=>false)); 
    1616    } 
    1717 
  • trunk/test/unit/lib/AkInstaller.php

    r323 r423  
    136136            description text, 
    137137            parent_id integer(11) not null default '0' 
    138         "); 
     138        ", array('timestamp'=>false)); 
    139139 
    140140 
     
    142142            category_id integer(11) not null, 
    143143            page_id integer(11) not null 
    144         "); 
     144        ", array('timestamp'=>false)); 
    145145 
    146146        $this->Installer->createTable('test_nice_urls', " 
     
    149149            context_id integer(11) not null, 
    150150            context string(255) not null default 'page' 
    151         "); 
     151        ", array('timestamp'=>false)); 
    152152 
    153153