From: Peter Rabbitson Date: Wed, 11 Feb 2009 08:24:58 +0000 (+0000) Subject: Test for resultset corruption by search() X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=1b374bf3746183ad4c6a4aeb40b1679e79a42fc9;p=dbsrgits%2FDBIx-Class-Historic.git Test for resultset corruption by search() --- diff --git a/t/77prefetch.t b/t/77prefetch.t index 608c8eb..d486ab4 100644 --- a/t/77prefetch.t +++ b/t/77prefetch.t @@ -2,6 +2,7 @@ use strict; use warnings; use Test::More; +use Test::Exception; use lib qw(t/lib); use DBICTest; use Data::Dumper; @@ -16,7 +17,7 @@ BEGIN { eval "use DBD::SQLite"; plan $@ ? ( skip_all => 'needs DBD::SQLite for testing' ) - : ( tests => 58 ); + : ( tests => 63 ); } # figure out if we've got a version of sqlite that is older than 3.2.6, in @@ -45,6 +46,27 @@ is(Dumper($search), $search_str, 'Search hash untouched after search()'); is(Dumper($attr), $attr_str, 'Attribute hash untouched after search()'); cmp_ok($rs + 0, '==', 3, 'Correct number of records returned'); +# A search() with prefetch seems to pollute an already joined resultset +# in a way that offsets future joins (adapted from a test case by Debolaz) +{ + my $cd_rs = $schema->resultset ('Producer')->first->cds; + my $attrs = Dumper $cd_rs->{attrs}; + + $cd_rs->search ({})->all; + is (Dumper ($cd_rs->{attrs}), $attrs, 'Resultset attributes preserved after a simple search'); + + lives_ok (sub { + $cd_rs->search ({'artist.artistid' => 1}, { prefetch => 'artist' })->all; + is (Dumper ($cd_rs->{attrs}), $attrs, 'Resultset attributes preserved after search with prefetch'); + }, 'first prefetching search ok'); + + lives_ok (sub { + $cd_rs->search ({'artist.artistid' => 1}, { prefetch => 'artist' })->all; + is (Dumper ($cd_rs->{attrs}), $attrs, 'Resultset attributes preserved after another search with prefetch') + }, 'second prefetching search ok'); +} + + my $queries = 0; $schema->storage->debugcb(sub { $queries++; }); $schema->storage->debug(1);