[Bast-commits] r6461 - in DBIx-Class/0.08/branches/order_by_refactor/t: . order

mo at dev.catalyst.perl.org mo at dev.catalyst.perl.org
Sat May 30 09:06:54 GMT 2009


Author: mo
Date: 2009-05-30 09:06:54 +0000 (Sat, 30 May 2009)
New Revision: 6461

Added:
   DBIx-Class/0.08/branches/order_by_refactor/t/order/
   DBIx-Class/0.08/branches/order_by_refactor/t/order/with_bind.t
Log:
order_by tests

Added: DBIx-Class/0.08/branches/order_by_refactor/t/order/with_bind.t
===================================================================
--- DBIx-Class/0.08/branches/order_by_refactor/t/order/with_bind.t	                        (rev 0)
+++ DBIx-Class/0.08/branches/order_by_refactor/t/order/with_bind.t	2009-05-30 09:06:54 UTC (rev 6461)
@@ -0,0 +1,93 @@
+use strict;
+use warnings;
+
+use Test::More;
+use lib qw(t/lib);
+use DBICTest;
+use DBIC::SqlMakerTest;
+
+my $schema = DBICTest->init_schema;
+
+my $rs = $schema->resultset('FourKeys');
+
+sub test_order {
+    my $args = shift;
+
+    my $req_order =
+      $args->{order_req}
+      ? "ORDER BY $args->{order_req}"
+      : '';
+
+    is_same_sql_bind(
+        $rs->search(
+            { foo => 'bar' },
+            {
+                order_by => $args->{order_by},
+                having =>
+                  [ { read_count => { '>' => 5 } }, \[ 'read_count < ?', 8 ] ]
+            }
+          )->as_query,
+        "(
+          SELECT me.foo, me.bar, me.hello, me.goodbye, me.sensors, me.read_count 
+          FROM fourkeys me 
+          WHERE ( foo = ? ) 
+          HAVING read_count > ? OR read_count < ?
+          $req_order
+        )",
+        [
+            [qw(foo bar)], [qw(read_count 5)],
+            8, $args->{bind} ? @{ $args->{bind} } : ()
+        ],
+    );
+}
+
+my @tests = (
+    {
+        order_by  => \'foo DESC',
+        order_req => 'foo DESC',
+        bind      => [],
+    },
+    {
+        order_by  => { -asc => 'foo' },
+        order_req => 'foo ASC',
+        bind      => [],
+    },
+    {
+        order_by  => { -desc => \[ 'colA LIKE ?', 'test' ] },
+        order_req => 'colA LIKE ? DESC',
+        bind      => [qw(test)],
+    },
+    {
+        order_by  => \[ 'colA LIKE ? DESC', 'test' ],
+        order_req => 'colA LIKE ? DESC',
+        bind      => [qw(test)],
+    },
+    {
+        order_by => [
+            { -asc  => \['colA'] },
+            { -desc => \[ 'colB LIKE ?', 'test' ] },
+            { -asc  => \[ 'colC LIKE ?', 'tost' ] }
+        ],
+        order_req => 'colA ASC, colB LIKE ? DESC, colC LIKE ? ASC',
+        bind      => [qw(test tost)],
+    },
+    {    # this would be really really nice!
+        order_by => [
+            { -asc  => 'colA' },
+            { -desc => { colB => { 'LIKE' => 'test' } } },
+            { -asc  => { colC => { 'LIKE' => 'tost' } } }
+        ],
+        order_req => 'colA ASC, colB LIKE ? DESC, colC LIKE ? ASC',
+        bind      => [ [ colB => 'test' ], [ colC => 'tost' ] ],      # ???
+    },
+    {
+        order_by  => { -desc => { colA  => { LIKE  => 'test' } } },
+        order_req => 'colA LIKE ? DESC',
+        bind      => [qw(test)],
+    },
+);
+
+plan( tests => scalar @tests );
+
+test_order($_) for @tests;
+




More information about the Bast-commits mailing list