[Bps-public-commit] r11365 - DBIx-SearchBuilder/trunk/t

ruz at bestpractical.com ruz at bestpractical.com
Tue Apr 1 22:47:43 EDT 2008


Author: ruz
Date: Tue Apr  1 22:47:43 2008
New Revision: 11365

Modified:
   DBIx-SearchBuilder/trunk/t/02order_outer.t

Log:
* update test

Modified: DBIx-SearchBuilder/trunk/t/02order_outer.t
==============================================================================
--- DBIx-SearchBuilder/trunk/t/02order_outer.t	(original)
+++ DBIx-SearchBuilder/trunk/t/02order_outer.t	Tue Apr  1 22:47:43 2008
@@ -28,7 +28,7 @@
 	my $ret = init_schema( 'TestApp', $handle );
 	isa_ok($ret,'DBI::st', "Inserted the schema. got a statement handle back");
 
-    my $lowest = $d ne 'Pg'? '-': 'z';
+    my $lowest = ($d ne 'Pg' && $d ne 'Oracle')? '-': 'z';
 
 diag "generate data" if $ENV{TEST_VERBOSE};
 {
@@ -55,8 +55,8 @@
     }
 }
 
-# test ASC order
-{
+# ASC order
+foreach my $direction ( qw(ASC DESC) ) {
     my $objs = TestApp::Objects->new($handle);
     $objs->UnLimit;
     my $tags_alias = $objs->Join(
@@ -67,47 +67,26 @@
         FIELD2 => 'Object',
     );
     ok($tags_alias, "joined tags table");
-    $objs->OrderBy( ALIAS => $tags_alias, FIELD => 'Name', ORDER => 'ASC' );
+    $objs->OrderBy( ALIAS => $tags_alias, FIELD => 'Name', ORDER => $direction );
 
     ok($objs->First, 'ok, we have at least one result');
     $objs->GotoFirstItem;
 
-    my ($order_ok, $last) = (1, '-');
+    my ($order_ok, $last) = (1, $direction eq 'ASC'? '-': 'zzzz');
     while ( my $obj = $objs->Next ) {
-        if ( (substr($last, 0, 1) cmp substr($obj->Name, 0, 1)) > 0 ) {
-            $order_ok = 0; last;
+        my $tmp;
+        if ( $direction eq 'ASC' ) {
+            $tmp = (substr($last, 0, 1) cmp substr($obj->Name, 0, 1));
+        } else {
+            $tmp = -(substr($last, -1, 1) cmp substr($obj->Name, -1, 1));
         }
-        $last = $obj->Name;
-    }
-    ok($order_ok, "order is correct") or diag "Wrong query: ". $objs->BuildSelectQuery;
-}
-
-# test DESC order
-{
-    my $objs = TestApp::Objects->new($handle);
-    $objs->UnLimit;
-    my $tags_alias = $objs->Join(
-        TYPE   => 'LEFT',
-        ALIAS1 => 'main',
-        FIELD1 => 'id',
-        TABLE2 => 'Tags',
-        FIELD2 => 'Object',
-    );
-    ok($tags_alias, "joined tags table");
-    $objs->OrderBy( ALIAS => $tags_alias, FIELD => 'Name', ORDER => 'DESC' );
-
-    ok($objs->First, 'ok, we have at least one result');
-    $objs->GotoFirstItem;
-
-    my ($order_ok, $last) = (1, 'z');
-    while ( my $obj = $objs->Next ) {
-        if ( (substr($last, -1, 1) cmp substr($obj->Name, -1, 1)) < 0 ) {
+        if ( $tmp > 0 ) {
             $order_ok = 0; last;
         }
         $last = $obj->Name;
     }
-    ok($order_ok, "order is correct") or do {
-        diag "Wrong query: ". $objs->BuildSelectQuery;
+    ok($order_ok, "$direction order is correct") or do {
+        diag "Wrong $direction query: ". $objs->BuildSelectQuery;
         $objs->GotoFirstItem;
         while ( my $obj = $objs->Next ) {
             diag($obj->id .":". $obj->Name);
@@ -175,8 +154,10 @@
 ] }
 
 sub cleanup_schema_oracle { [
-    "DROP SEQUENCE Users_seq",
-    "DROP TABLE Users", 
+    "DROP SEQUENCE Objects_seq",
+    "DROP TABLE Objects", 
+    "DROP SEQUENCE Tags_seq",
+    "DROP TABLE Tags", 
 ] }
 
 
@@ -242,7 +223,7 @@
         {read => 1, type => 'int(11)' },
         Object =>
         {read => 1, type => 'int(11)' },
-        Value =>
+        Name =>
         {read => 1, write => 1, type => 'varchar(36)' },
     }
 }



More information about the Bps-public-commit mailing list