Commit | Line | Data |
95a70f01 |
1 | use strict; |
2 | use Test::More; |
3 | |
4 | BEGIN { |
289ba852 |
5 | eval "use DBIx::Class::CDBICompat;"; |
6 | if ($@) { |
7 | plan (skip_all => 'Class::Trigger and DBIx::ContextualFetch required'); |
8 | next; |
9 | } |
10 | eval "use DBD::SQLite"; |
11 | plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 33); |
95a70f01 |
12 | } |
13 | |
14 | use lib 't/testlib'; |
15 | use Film; |
16 | |
223b8fe3 |
17 | my $it_class = "DBIx::Class::ResultSet"; |
95a70f01 |
18 | |
19 | my @film = ( |
20 | Film->create({ Title => 'Film 1' }), |
21 | Film->create({ Title => 'Film 2' }), |
22 | Film->create({ Title => 'Film 3' }), |
23 | Film->create({ Title => 'Film 4' }), |
24 | Film->create({ Title => 'Film 5' }), |
25 | Film->create({ Title => 'Film 6' }), |
26 | ); |
27 | |
28 | { |
29 | my $it1 = Film->retrieve_all; |
30 | isa_ok $it1, $it_class; |
31 | |
32 | my $it2 = Film->retrieve_all; |
33 | isa_ok $it2, $it_class; |
34 | |
35 | while (my $from1 = $it1->next) { |
36 | my $from2 = $it2->next; |
37 | is $from1->id, $from2->id, "Both iterators get $from1"; |
38 | } |
39 | } |
40 | |
41 | { |
42 | my $it = Film->retrieve_all; |
43 | is $it->first->title, "Film 1", "Film 1 first"; |
44 | is $it->next->title, "Film 2", "Film 2 next"; |
45 | is $it->first->title, "Film 1", "First goes back to 1"; |
46 | is $it->next->title, "Film 2", "With 2 still next"; |
47 | $it->reset; |
48 | is $it->next->title, "Film 1", "Reset brings us to film 1 again"; |
49 | is $it->next->title, "Film 2", "And 2 is still next"; |
50 | } |
51 | |
52 | SKIP: { |
525035fb |
53 | #skip "Iterator doesn't yet have slice support", 19; |
95a70f01 |
54 | |
55 | { |
56 | my $it = Film->retrieve_all; |
57 | my @slice = $it->slice(2,4); |
58 | is @slice, 3, "correct slice size (array)"; |
59 | is $slice[0]->title, "Film 3", "Film 3 first"; |
60 | is $slice[2]->title, "Film 5", "Film 5 last"; |
61 | } |
62 | |
63 | { |
64 | my $it = Film->retrieve_all; |
65 | my $slice = $it->slice(2,4); |
66 | isa_ok $slice, $it_class, "slice as iterator"; |
67 | is $slice->count, 3,"correct slice size (array)"; |
68 | is $slice->first->title, "Film 3", "Film 3 first"; |
69 | is $slice->next->title, "Film 4", "Film 4 next"; |
70 | is $slice->first->title, "Film 3", "First goes back to 3"; |
71 | is $slice->next->title, "Film 4", "With 4 still next"; |
72 | $slice->reset; |
73 | is $slice->next->title, "Film 3", "Reset brings us to film 3 again"; |
74 | is $slice->next->title, "Film 4", "And 4 is still next"; |
75 | |
76 | # check if the original iterator still works |
77 | is $it->count, 6, "back to the original iterator, is of right size"; |
78 | is $it->first->title, "Film 1", "Film 1 first"; |
79 | is $it->next->title, "Film 2", "Film 2 next"; |
80 | is $it->first->title, "Film 1", "First goes back to 1"; |
81 | is $it->next->title, "Film 2", "With 2 still next"; |
82 | is $it->next->title, "Film 3", "Film 3 is still in original Iterator"; |
83 | $it->reset; |
84 | is $it->next->title, "Film 1", "Reset brings us to film 1 again"; |
85 | is $it->next->title, "Film 2", "And 2 is still next"; |
86 | } |
87 | |
88 | } # End SKIP |