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