File: OrderByMagic.t

package info (click to toggle)
libdbix-class-helpers-perl 2.036000-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,008 kB
  • sloc: perl: 5,041; sql: 537; makefile: 7
file content (32 lines) | stat: -rw-r--r-- 781 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!perl

use strict;
use warnings;

use lib 't/lib';
use Test::More;
use Test::Deep;

use TestSchema;
my $schema = TestSchema->deploy_or_connect();
$schema->prepopulate;

my $rs = $schema->resultset('Foo');

my %tests = (
    'id'         => [{ -asc => 'me.id' }],
    '!id'        => [{ -desc => 'me.id' }],
    'id,!bar_id'   => [{ -asc => 'me.id' }, { -desc => 'bar_id' }],
    'id, !bar_id'  => [{ -asc => 'me.id' }, { -desc => 'bar_id' }],
    'id ,!bar_id'  => [{ -asc => 'me.id' }, { -desc => 'bar_id' }],
    'id , !bar_id' => [{ -asc => 'me.id' }, { -desc => 'bar_id' }],
);

while (my ($order, $expect) = each(%tests)) {
   cmp_deeply
      [$rs->order_by($order)->all],
      [$rs->search({},{order_by => $expect})->all],
      "order_by works: $order";
}

done_testing;