X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fsqlahacks%2Forder_by_func.t;h=1caac14738d386349adf918db88fb89a5d9521d4;hb=ba42e08cae27496c32d44d3987ac566099140aaf;hp=51968ed0937f974e63c048ce1476506f29655381;hpb=5e120ab6a144761854254b82527fac3088cc8d71;p=dbsrgits%2FDBIx-Class.git diff --git a/t/sqlahacks/order_by_func.t b/t/sqlahacks/order_by_func.t index 51968ed..1caac14 100644 --- a/t/sqlahacks/order_by_func.t +++ b/t/sqlahacks/order_by_func.t @@ -7,29 +7,45 @@ use DBICTest; use DBIC::SqlMakerTest; my $schema = DBICTest->init_schema(); +$schema->storage->sql_maker->quote_char ('"'); +$schema->storage->sql_maker->name_sep ('.'); my $rs = $schema->resultset('CD')->search({}, { 'join' => 'tracks', - order_by => { + order_by => [ + { -length => 'me.title' }, + { -desc => { - count => 'tracks.track_id', + count => 'tracks.trackid', }, - }, + }, + ], distinct => 1, rows => 2, - page => 1, + page => 2, }); -my $match = q{ - SELECT me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track FROM cd me - GROUP BY me.cdid, me.artist, me.title, me.year, me.genreid, me.single_track - ORDER BY COUNT(tracks.trackid) DESC -}; -TODO: { - todo_skip 'order_by using function', 2; - is_same_sql($rs->as_query, $match, 'order by with func query'); +is_same_sql_bind( + $rs->as_query, + '( + SELECT "me"."cdid", "me"."artist", "me"."title", "me"."year", "me"."genreid", "me"."single_track" + FROM cd "me" + LEFT JOIN "track" "tracks" ON "tracks"."cd" = "me"."cdid" + GROUP BY "me"."cdid", "me"."artist", "me"."title", "me"."year", "me"."genreid", "me"."single_track" + ORDER BY + LENGTH( "me"."title" ), + COUNT( "tracks"."trackid" ) DESC + LIMIT 2 OFFSET 2 + )', + [], + 'order by with func query', +); - ok($rs->count == 2, 'amount of rows return in order by func query'); -} +ok($rs->count_rs->next == 2, 'amount of rows return in order by func query'); +is_deeply ( + [ $rs->get_column ('me.title')->all ], + [ "Caterwaulin' Blues", "Come Be Depressed With Us" ], + 'Correctly ordered stuff by title-length', +); done_testing;