cleanup test by wreis
[dbsrgits/DBIx-Class.git] / t / sqlahacks / order_by_func.t
1 use strict;
2 use warnings;
3 use Test::More;
4
5 use lib qw(t/lib);
6 use DBICTest;
7 use DBIC::SqlMakerTest;
8
9 my $schema = DBICTest->init_schema();
10 $schema->storage->sql_maker->quote_char ('"');
11 $schema->storage->sql_maker->name_sep ('.');
12
13 my $rs = $schema->resultset('CD')->search({}, {
14     'join' => 'tracks',
15     order_by => [
16       { -length => 'me.title' },
17       {
18         -desc => {
19             count => 'tracks.trackid',
20         },
21       },
22     ],
23     distinct => 1,
24     rows => 2,
25     page => 2,
26 });
27
28 is_same_sql_bind(
29   $rs->as_query,
30   '(
31     SELECT "me"."cdid", "me"."artist", "me"."title", "me"."year", "me"."genreid", "me"."single_track"
32       FROM cd "me"
33       LEFT JOIN "track" "tracks" ON "tracks"."cd" = "me"."cdid"
34     GROUP BY "me"."cdid", "me"."artist", "me"."title", "me"."year", "me"."genreid", "me"."single_track"
35     ORDER BY
36       LENGTH( "me"."title" ),
37       COUNT( "tracks"."trackid" ) DESC
38     LIMIT 2 OFFSET 2
39   )',
40   [],
41   'order by with func query',
42 );
43
44 ok($rs->count_rs->next == 2, 'amount of rows return in order by func query');
45 is_deeply (
46   [ $rs->get_column ('me.title')->all ],
47   [ "Caterwaulin' Blues", "Come Be Depressed With Us" ],
48   'Correctly ordered stuff by title-length',
49 );
50
51 done_testing;