Show
Ignore:
Timestamp:
06/04/08 01:21:49 (18 months ago)
Author:
fumiakiy
Message:

Modernized how sort argument is specified in group_by query. BugId:79977. The legacy way of specifying it is still allowed but discouraged.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • branches/release-39/t/driver-tests.pl

    r2475 r2500  
    3333} 
    3434 
    35 plan tests => 184; 
     35plan tests => 197; 
    3636 
    3737package Zot; 
     
    400400sleep(2);  ## Sleep to ensure created_on timestamps are unique 
    401401 
     402# legacy way of specifying sort direction 
    402403my $cgb_iter = Bar->count_group_by({ 
    403404        status => '0', 
    404405    }, { 
    405406        group => [ 'foo_id' ], 
    406         sort => 'foo_id', 
    407         direction => 'descend', 
     407        sort => 'foo_id desc', 
    408408    }); 
    409409my ($count, $bfid, $month); 
     
    417417ok(!$cgb_iter->(), 'no $iter'); 
    418418 
    419 $cgb_iter = Bar->count_group_by(undef, { 
     419# new way of specifying sort direction 
     420my $cgb_iter2 = Bar->count_group_by({ 
     421        status => '0', 
     422    }, { 
     423        group => [ 'foo_id' ], 
     424        sort => 'foo_id', 
     425        direction => 'descend' 
     426    }); 
     427 
     428isa_ok($cgb_iter2, 'CODE'); 
     429ok(($count, $bfid) = $cgb_iter2->(), 'set'); 
     430is($bfid, $bar[1]->id, 'id'); 
     431is($count, 1, 'count4'); 
     432ok(($count, $bfid) = $cgb_iter2->(), 'set'); 
     433is($bfid, $bar[0]->id, 'id'); 
     434is($count, 1, 'count5'); 
     435ok(!$cgb_iter2->(), 'no $iter'); 
     436 
     437# legacy way of specifying sort direction 
     438my $cgb_iter3 = Bar->count_group_by(undef, { 
    420439        group => [ 'extract(month from created_on)' ], 
    421         sort => 'extract(month from created_on)', 
    422         direction => 'descend', 
     440        sort => 'extract(month from created_on) desc', 
    423441    }); 
    424 isa_ok($cgb_iter, 'CODE'); 
    425 ok(($count, $month) = $cgb_iter->(), 'set'); 
     442isa_ok($cgb_iter3, 'CODE'); 
     443ok(($count, $month) = $cgb_iter3->(), 'set'); 
    426444use POSIX qw(strftime); 
    427445is(int($month), int(strftime("%m", localtime)), 'month'); 
    428446is($count, 3, 'count6'); 
    429 ok(!$cgb_iter->(), 'no $iter'); 
     447ok(!$cgb_iter3->(), 'no $iter'); 
     448 
     449# new way of specifying sort direction 
     450my $cgb_iter4 = Bar->count_group_by(undef, { 
     451        group => [ 'extract(month from created_on)' ], 
     452        sort => [{ column => 'extract(month from created_on)', 
     453            desc => 'desc' }] 
     454    }); 
     455isa_ok($cgb_iter4, 'CODE'); 
     456ok(($count, $month) = $cgb_iter4->(), 'set'); 
     457is(int($month), int(strftime("%m", localtime)), 'month'); 
     458is($count, 3, 'count6'); 
     459ok(!$cgb_iter4->(), 'no $iter'); 
    430460 
    431461## Get a count of all Foo objects in order of most recently