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