9 my $schema = DBICTest->init_schema();
11 my $rs = $schema->resultset('Artist')->search({}, {
13 prefetch => { cds => 'tracks' },
16 my $initial_artists_cnt = $rs->count;
18 # create one extra artist with just one cd with just one track
19 # and then an artist with nothing at all
20 # the implicit order by me.artistid will get them back in correct order
31 $rs->create({ name => 'bar' });
32 $rs->create({ name => 'baz' });
34 # make sure we are reentrant, and also check with explicit order_by
35 for (undef, undef, 'me.artistid') {
36 $rs = $rs->search({}, { order_by => $_ }) if $_;
38 for (1 .. $initial_artists_cnt) {
39 is ($rs->next->artistid, $_, 'Default fixture artists in order') || exit;
42 my $foo_artist = $rs->next;
43 is ($foo_artist->cds->next->tracks->next->title, 'footrack', 'Right track');
46 [$rs->cursor->next]->[0],
47 $initial_artists_cnt + 3,
48 'Very last artist still on the cursor'
51 is_deeply ([$rs->cursor->next], [], 'Nothing else left');
53 is ($rs->next->artistid, $initial_artists_cnt + 2, 'Row stashed in resultset still accessible');
54 is ($rs->next, undef, 'Nothing left in resultset either');
62 is (@objs, $initial_artists_cnt + 3, '->all resets everything correctly');
63 is ( ($rs->cursor->next)[0], 1, 'Cursor auto-rewound after all()');
64 is ($rs->{stashed_rows}, undef, 'Nothing else left in $rs stash');
66 my $unordered_rs = $rs->search({}, { order_by => 'cds.title' });
67 ok ($unordered_rs->next, 'got row 1');
68 is_deeply ([$unordered_rs->cursor->next], [], 'Nothing left on cursor, eager slurp');
69 ok ($unordered_rs->next, "got row $_") for (2 .. $initial_artists_cnt + 3);
70 is ($unordered_rs->next, undef, 'End of RS reached');
71 is ($unordered_rs->next, undef, 'End of RS not lost');