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