X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fprefetch%2Ffalse_colvalues.t;h=a87de706a6ad046260fdc8673618ab893cce7340;hb=c0329273268971824784f239f32c7246e68da9c5;hp=4520bf4b0c9434684a861a91993fcfa0d92e952e;hpb=52864fbd5c6035f8f3961173ad05c2cc58fe9a34;p=dbsrgits%2FDBIx-Class-Historic.git diff --git a/t/prefetch/false_colvalues.t b/t/prefetch/false_colvalues.t index 4520bf4..a87de70 100644 --- a/t/prefetch/false_colvalues.t +++ b/t/prefetch/false_colvalues.t @@ -1,65 +1,36 @@ +BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) } + use warnings; use strict; use Test::More; use Test::Deep; -use lib qw(t/lib); + use DBICTest; -my $schema = DBICTest->init_schema( - no_populate => 1, -); +my $schema = DBICTest->init_schema( no_populate => 1 ); $schema->resultset('CD')->create({ - cdid => 0, - artist => { - artistid => 0, - name => '', - rank => 0, - charfield => 0, - }, - title => '', - year => 0, - genreid => 0, - single_track => 0, -}); - -my $orig_debug = $schema->storage->debug; - -my $queries = 0; -$schema->storage->debugcb(sub { $queries++; }); -$schema->storage->debug(1); - -my $cd = $schema->resultset('CD')->search( {}, { prefetch => 'artist' })->next; - -cmp_deeply - { $cd->get_columns }, - { - artist => 0, - cdid => 0, - genreid => 0, - single_track => 0, - title => '', - year => 0, - }, - 'Expected CD columns present', -; - -cmp_deeply - { $cd->artist->get_columns }, - { - artistid => 0, - charfield => 0, - name => "", - rank => 0, + cdid => 0, title => '', year => 0, genreid => 0, single_track => 0, artist => { + artistid => 0, name => '', rank => 0, charfield => 0, }, - 'Expected Artist columns present', -; - -is $queries, 1, 'Only one query fired - prefetch worked'; +}); -$schema->storage->debugcb(undef); -$schema->storage->debug($orig_debug); +$schema->is_executed_querycount( sub { + my $cd = $schema->resultset('CD')->search( {}, { prefetch => 'artist' })->next; + + cmp_deeply + { $cd->get_columns }, + { artist => 0, cdid => 0, genreid => 0, single_track => 0, title => '', year => 0 }, + 'Expected CD columns present', + ; + + cmp_deeply + { $cd->artist->get_columns }, + { artistid => 0, charfield => 0, name => "", rank => 0 }, + 'Expected Artist columns present', + ; +}, 1, 'Only one query fired - prefetch worked' ); done_testing;