Move replicated to Opt::Deps
[dbsrgits/DBIx-Class.git] / t / bind / order_by.t
CommitLineData
0c033974 1use strict;
2use warnings;
3
4use Test::More;
a2368d30 5use Test::Exception;
0c033974 6use lib qw(t/lib);
7use DBICTest;
8use DBIC::SqlMakerTest;
9
10my $schema = DBICTest->init_schema;
11
12my $rs = $schema->resultset('FourKeys');
13
14sub test_order {
a2368d30 15
16 TODO: {
0c033974 17 my $args = shift;
18
a2368d30 19 local $TODO = "Not implemented" if $args->{todo};
0c033974 20
a2368d30 21 lives_ok {
22 is_same_sql_bind(
0c033974 23 $rs->search(
24 { foo => 'bar' },
25 {
26 order_by => $args->{order_by},
27 having =>
28 [ { read_count => { '>' => 5 } }, \[ 'read_count < ?', 8 ] ]
29 }
30 )->as_query,
31 "(
32 SELECT me.foo, me.bar, me.hello, me.goodbye, me.sensors, me.read_count
33 FROM fourkeys me
34 WHERE ( foo = ? )
35 HAVING read_count > ? OR read_count < ?
a2368d30 36 ORDER BY $args->{order_req}
0c033974 37 )",
38 [
a2368d30 39 [qw(foo bar)],
40 [qw(read_count 5)],
41 8,
42 $args->{bind}
43 ? @{ $args->{bind} }
44 : ()
0c033974 45 ],
a2368d30 46 );
47 };
48 fail('Fail the unfinished is_same_sql_bind') if $@;
49 }
0c033974 50}
51
52my @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 {
64 order_by => { -desc => \[ 'colA LIKE ?', 'test' ] },
65 order_req => 'colA LIKE ? DESC',
66 bind => [qw(test)],
67 },
68 {
69 order_by => \[ 'colA LIKE ? DESC', 'test' ],
70 order_req => 'colA LIKE ? DESC',
71 bind => [qw(test)],
72 },
73 {
74 order_by => [
75 { -asc => \['colA'] },
76 { -desc => \[ 'colB LIKE ?', 'test' ] },
77 { -asc => \[ 'colC LIKE ?', 'tost' ] }
78 ],
79 order_req => 'colA ASC, colB LIKE ? DESC, colC LIKE ? ASC',
80 bind => [qw(test tost)],
81 },
a2368d30 82
83 # (mo) this would be really really nice!
84 # (ribasushi) I don't think so, not writing it - patches welcome
85 {
0c033974 86 order_by => [
87 { -asc => 'colA' },
88 { -desc => { colB => { 'LIKE' => 'test' } } },
89 { -asc => { colC => { 'LIKE' => 'tost' } } }
90 ],
91 order_req => 'colA ASC, colB LIKE ? DESC, colC LIKE ? ASC',
92 bind => [ [ colB => 'test' ], [ colC => 'tost' ] ], # ???
a2368d30 93 todo => 1,
0c033974 94 },
95 {
96 order_by => { -desc => { colA => { LIKE => 'test' } } },
97 order_req => 'colA LIKE ? DESC',
98 bind => [qw(test)],
a2368d30 99 todo => 1,
0c033974 100 },
101);
102
a2368d30 103plan( tests => scalar @tests * 2 );
0c033974 104
105test_order($_) for @tests;
106