Commit | Line | Data |
e60dc79f |
1 | use Test::More; |
2 | |
3 | use strict; |
4 | use warnings; |
5 | |
6 | BEGIN { |
7 | eval "use DBIx::Class::CDBICompat;"; |
8 | if ($@) { |
9 | plan (skip_all => "Class::Trigger and DBIx::ContextualFetch required: $@"); |
e60dc79f |
10 | } |
68de9438 |
11 | plan tests => 10; |
e60dc79f |
12 | } |
13 | |
14 | INIT { |
6a3bf251 |
15 | use lib 't/cdbi/testlib'; |
16 | use Film; |
e60dc79f |
17 | } |
18 | |
19 | |
20 | Film->create({ Title => $_, Rating => "PG" }) for ("Superman", "Super Fuzz"); |
21 | Film->create({ Title => "Batman", Rating => "PG13" }); |
22 | |
23 | my $superman = Film->search_where( Title => "Superman" ); |
24 | is $superman->next->Title, "Superman", "search_where() as iterator"; |
25 | is $superman->next, undef; |
26 | |
d37c21dc |
27 | { |
28 | my @supers = Film->search_where({ title => { 'like' => 'Super%' } }); |
29 | is_deeply [sort map $_->Title, @supers], |
30 | [sort ("Super Fuzz", "Superman")], 'like'; |
31 | } |
32 | |
33 | |
e60dc79f |
34 | my @all = Film->search_where({}, { order_by => "Title ASC" }); |
35 | is_deeply ["Batman", "Super Fuzz", "Superman"], |
36 | [map $_->Title, @all], |
37 | "order_by ASC"; |
38 | |
39 | @all = Film->search_where({}, { order_by => "Title DESC" }); |
40 | is_deeply ["Superman", "Super Fuzz", "Batman"], |
41 | [map $_->Title, @all], |
42 | "order_by DESC"; |
43 | |
44 | @all = Film->search_where({ Rating => "PG" }, { limit => 1, order_by => "Title ASC" }); |
45 | is_deeply ["Super Fuzz"], |
46 | [map $_->Title, @all], |
47 | "where, limit"; |
48 | |
49 | @all = Film->search_where({}, { limit => 2, order_by => "Title ASC" }); |
50 | is_deeply ["Batman", "Super Fuzz"], |
51 | [map $_->Title, @all], |
52 | "limit"; |
53 | |
54 | @all = Film->search_where({}, { offset => 1, order_by => "Title ASC" }); |
55 | is_deeply ["Super Fuzz", "Superman"], |
56 | [map $_->Title, @all], |
57 | "offset"; |
58 | |
59 | @all = Film->search_where({}, { limit => 1, offset => 1, order_by => "Title ASC" }); |
60 | is_deeply ["Super Fuzz"], |
61 | [map $_->Title, @all], |
62 | "limit + offset"; |
63 | |
64 | @all = Film->search_where({}, { limit => 2, offset => 1, |
65 | limit_dialect => "Top", order_by => "Title ASC" |
66 | }); |
67 | is_deeply ["Super Fuzz", "Superman"], |
68 | [map $_->Title, @all], |
69 | "limit_dialect ignored"; |
70 | |