Commit | Line | Data |
0c033974 |
1 | use strict; |
2 | use warnings; |
3 | |
4 | use Test::More; |
a2368d30 |
5 | use Test::Exception; |
a17640f1 |
6 | use Data::Dumper::Concise; |
0c033974 |
7 | use lib qw(t/lib); |
8 | use DBICTest; |
9 | use DBIC::SqlMakerTest; |
10 | |
11 | my $schema = DBICTest->init_schema; |
12 | |
13 | my $rs = $schema->resultset('FourKeys'); |
14 | |
15 | sub test_order { |
a2368d30 |
16 | |
17 | TODO: { |
0c033974 |
18 | my $args = shift; |
19 | |
a2368d30 |
20 | local $TODO = "Not implemented" if $args->{todo}; |
0c033974 |
21 | |
a2368d30 |
22 | lives_ok { |
23 | is_same_sql_bind( |
0c033974 |
24 | $rs->search( |
25 | { foo => 'bar' }, |
26 | { |
27 | order_by => $args->{order_by}, |
28 | having => |
a17640f1 |
29 | [ { read_count => { '>' => 5 } }, \[ 'read_count < ?', [ read_count => 8 ] ] ] |
0c033974 |
30 | } |
31 | )->as_query, |
32 | "( |
33 | SELECT me.foo, me.bar, me.hello, me.goodbye, me.sensors, me.read_count |
34 | FROM fourkeys me |
35 | WHERE ( foo = ? ) |
36 | HAVING read_count > ? OR read_count < ? |
a2368d30 |
37 | ORDER BY $args->{order_req} |
0c033974 |
38 | )", |
39 | [ |
a2368d30 |
40 | [qw(foo bar)], |
41 | [qw(read_count 5)], |
a17640f1 |
42 | [qw(read_count 8)], |
a2368d30 |
43 | $args->{bind} |
44 | ? @{ $args->{bind} } |
45 | : () |
0c033974 |
46 | ], |
a17640f1 |
47 | ) || diag Dumper $args->{order_by}; |
a2368d30 |
48 | }; |
a2368d30 |
49 | } |
0c033974 |
50 | } |
51 | |
52 | my @tests = ( |
53 | { |
54 | order_by => \'foo DESC', |
55 | order_req => 'foo DESC', |
56 | bind => [], |
57 | }, |
58 | { |
59 | order_by => { -asc => 'foo' }, |
60 | order_req => 'foo ASC', |
61 | bind => [], |
62 | }, |
63 | { |
a17640f1 |
64 | order_by => { -desc => \[ 'colA LIKE ?', [ colA => 'test' ] ] }, |
0c033974 |
65 | order_req => 'colA LIKE ? DESC', |
a17640f1 |
66 | bind => [ [ colA => 'test' ] ], |
0c033974 |
67 | }, |
68 | { |
a17640f1 |
69 | order_by => \[ 'colA LIKE ? DESC', [ colA => 'test' ] ], |
0c033974 |
70 | order_req => 'colA LIKE ? DESC', |
a17640f1 |
71 | bind => [ [ colA => 'test' ] ], |
0c033974 |
72 | }, |
73 | { |
74 | order_by => [ |
75 | { -asc => \['colA'] }, |
a17640f1 |
76 | { -desc => \[ 'colB LIKE ?', [ colB => 'test' ] ] }, |
77 | { -asc => \[ 'colC LIKE ?', [ colC => 'tost' ] ] }, |
0c033974 |
78 | ], |
79 | order_req => 'colA ASC, colB LIKE ? DESC, colC LIKE ? ASC', |
a17640f1 |
80 | bind => [ [ colB => 'test' ], [ colC => 'tost' ] ], |
0c033974 |
81 | }, |
a2368d30 |
82 | { |
a17640f1 |
83 | todo => 1, |
0c033974 |
84 | order_by => [ |
85 | { -asc => 'colA' }, |
86 | { -desc => { colB => { 'LIKE' => 'test' } } }, |
87 | { -asc => { colC => { 'LIKE' => 'tost' } } } |
88 | ], |
89 | order_req => 'colA ASC, colB LIKE ? DESC, colC LIKE ? ASC', |
a17640f1 |
90 | bind => [ [ colB => 'test' ], [ colC => 'tost' ] ], |
0c033974 |
91 | }, |
92 | { |
a17640f1 |
93 | todo => 1, |
0c033974 |
94 | order_by => { -desc => { colA => { LIKE => 'test' } } }, |
95 | order_req => 'colA LIKE ? DESC', |
a17640f1 |
96 | bind => [ [ colA => 'test' ] ], |
0c033974 |
97 | }, |
98 | ); |
99 | |
0c033974 |
100 | test_order($_) for @tests; |
22912b45 |
101 | |
a17640f1 |
102 | done_testing; |