1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
12 my $schema = DBICTest->init_schema();
14 my $rs = $schema->resultset('Artist')->search({}, {
16 prefetch => { cds => 'tracks' },
19 my $initial_artists_cnt = $rs->count;
21 # create one extra artist with just one cd with just one track
22 # and then an artist with nothing at all
23 # the implicit order by me.artistid will get them back in correct order
34 $rs->create({ name => 'bar' });
35 $rs->create({ name => 'baz' });
37 # make sure we are reentrant, and also check with explicit order_by
38 for (undef, undef, 'me.artistid') {
39 $rs = $rs->search({}, { order_by => $_ }) if $_;
41 for (1 .. $initial_artists_cnt) {
42 is ($rs->next->artistid, $_, 'Default fixture artists in order') || exit;
45 my $foo_artist = $rs->next;
46 is ($foo_artist->cds->next->tracks->next->title, 'footrack', 'Right track');
49 [$rs->cursor->next]->[0],
50 $initial_artists_cnt + 3,
51 'Very last artist still on the cursor'
54 is_deeply ([$rs->cursor->next], [], 'Nothing else left');
56 is ($rs->next->artistid, $initial_artists_cnt + 2, 'Row stashed in resultset still accessible');
57 is ($rs->next, undef, 'Nothing left in resultset either');
65 is (@objs, $initial_artists_cnt + 3, '->all resets everything correctly');
66 is ( ($rs->cursor->next)[0], 1, 'Cursor auto-rewound after all()');
67 ok (! @{ $rs->{_stashed_rows} || [] }, 'Nothing else left in $rs stash');
69 my $unordered_rs = $rs->search({}, { order_by => 'cds.title' });
72 ok ($unordered_rs->next, 'got row 1');
73 } qr/performed an eager cursor slurp underneath/, 'Warned on auto-eager cursor';
75 is_deeply ([$unordered_rs->cursor->next], [], 'Nothing left on cursor, eager slurp');
76 ok ($unordered_rs->next, "got row $_") for (2 .. $initial_artists_cnt + 3);
77 is ($unordered_rs->next, undef, 'End of RS reached');
78 is ($unordered_rs->next, undef, 'End of RS not lost');
81 my $non_uniquely_ordered_constrained = $schema->resultset('CD')->search(
83 { order_by => [qw( me.genreid me.title me.year )], prefetch => 'tracks' },
86 isa_ok ($non_uniquely_ordered_constrained->next, 'DBICTest::CD' );
88 ok( defined $non_uniquely_ordered_constrained->cursor->next, 'Cursor not exhausted' );