10 my $schema = DBICTest->init_schema();
12 my $rs = $schema->resultset('Artist')->search({}, {
14 prefetch => { cds => 'tracks' },
17 my $initial_artists_cnt = $rs->count;
19 # create one extra artist with just one cd with just one track
20 # and then an artist with nothing at all
21 # the implicit order by me.artistid will get them back in correct order
32 $rs->create({ name => 'bar' });
33 $rs->create({ name => 'baz' });
35 # make sure we are reentrant, and also check with explicit order_by
36 for (undef, undef, 'me.artistid') {
37 $rs = $rs->search({}, { order_by => $_ }) if $_;
39 for (1 .. $initial_artists_cnt) {
40 is ($rs->next->artistid, $_, 'Default fixture artists in order') || exit;
43 my $foo_artist = $rs->next;
44 is ($foo_artist->cds->next->tracks->next->title, 'footrack', 'Right track');
47 [$rs->cursor->next]->[0],
48 $initial_artists_cnt + 3,
49 'Very last artist still on the cursor'
52 is_deeply ([$rs->cursor->next], [], 'Nothing else left');
54 is ($rs->next->artistid, $initial_artists_cnt + 2, 'Row stashed in resultset still accessible');
55 is ($rs->next, undef, 'Nothing left in resultset either');
63 is (@objs, $initial_artists_cnt + 3, '->all resets everything correctly');
64 is ( ($rs->cursor->next)[0], 1, 'Cursor auto-rewound after all()');
65 is ($rs->{_stashed_rows}, undef, 'Nothing else left in $rs stash');
67 my $unordered_rs = $rs->search({}, { order_by => 'cds.title' });
70 ok ($unordered_rs->next, 'got row 1');
71 } qr/performed an eager cursor slurp underneath/, 'Warned on auto-eager cursor';
73 is_deeply ([$unordered_rs->cursor->next], [], 'Nothing left on cursor, eager slurp');
74 ok ($unordered_rs->next, "got row $_") for (2 .. $initial_artists_cnt + 3);
75 is ($unordered_rs->next, undef, 'End of RS reached');
76 is ($unordered_rs->next, undef, 'End of RS not lost');
79 my $non_uniquely_ordered_constrained = $schema->resultset('CD')->search(
81 { order_by => [qw( me.genreid me.title me.year )], prefetch => 'tracks' },
84 isa_ok ($non_uniquely_ordered_constrained->next, 'DBICTest::CD' );
86 ok( defined $non_uniquely_ordered_constrained->cursor->next, 'Cursor not exhausted' );