5 eval "use DBIx::Class::CDBICompat;";
7 plan (skip_all => "Class::Trigger and DBIx::ContextualFetch required: $@");
10 eval "use DBD::SQLite";
11 plan $@ ? (skip_all => 'needs DBD::SQLite for testing') : (tests => 37);
14 use lib 't/cdbi/testlib';
17 my $it_class = "DBIx::Class::ResultSet";
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' }),
29 my $it1 = Film->retrieve_all;
30 isa_ok $it1, $it_class;
32 my $it2 = Film->retrieve_all;
33 isa_ok $it2, $it_class;
35 while (my $from1 = $it1->next) {
36 my $from2 = $it2->next;
37 is $from1->id, $from2->id, "Both iterators get $from1";
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";
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";
54 my $it = Film->retrieve_all;
55 my @slice = $it->slice(2,4);
56 is @slice, 3, "correct slice size (array)";
57 is $slice[0]->title, "Film 3", "Film 3 first";
58 is $slice[2]->title, "Film 5", "Film 5 last";
62 my $it = Film->retrieve_all;
63 my $slice = $it->slice(2,4);
64 isa_ok $slice, $it_class, "slice as iterator";
65 is $slice->count, 3,"correct slice size (array)";
66 is $slice->first->title, "Film 3", "Film 3 first";
67 is $slice->next->title, "Film 4", "Film 4 next";
68 is $slice->first->title, "Film 3", "First goes back to 3";
69 is $slice->next->title, "Film 4", "With 4 still next";
71 is $slice->next->title, "Film 3", "Reset brings us to film 3 again";
72 is $slice->next->title, "Film 4", "And 4 is still next";
74 # check if the original iterator still works
75 is $it->count, 6, "back to the original iterator, is of right size";
76 is $it->first->title, "Film 1", "Film 1 first";
77 is $it->next->title, "Film 2", "Film 2 next";
78 is $it->first->title, "Film 1", "First goes back to 1";
79 is $it->next->title, "Film 2", "With 2 still next";
80 is $it->next->title, "Film 3", "Film 3 is still in original Iterator";
82 is $it->next->title, "Film 1", "Reset brings us to film 1 again";
83 is $it->next->title, "Film 2", "And 2 is still next";
87 my $it = Film->retrieve_all;
88 is $it, $it->count, "iterator returns count as a scalar";
89 ok $it, "iterator returns true when there are results";
93 my $it = Film->search( Title => "something which does not exist" );
95 ok !$it, "iterator returns false when no results";