From: Peter Rabbitson Date: Sun, 18 Nov 2012 20:08:58 +0000 (+0100) Subject: Rename and expand false-value prefetch test X-Git-Tag: v0.08205~104 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=dbsrgits%2FDBIx-Class.git;a=commitdiff_plain;h=f4e13e1312bfdc2e1f6f0e2dde54779452570e3b Rename and expand false-value prefetch test --- diff --git a/TODO_SHORTTERM b/TODO_SHORTTERM index 434b01f..b4a6899 100644 --- a/TODO_SHORTTERM +++ b/TODO_SHORTTERM @@ -7,6 +7,5 @@ bullshit will we ever fix it? * 461c7168 has two places where it sets a brand new lexical to undef. Please remove for the sanity of future maintainers (avoid the "why is this here?!") -* 571df676 adds a bugs.t - please rename the test to something sensible * a48693f4 adds 5 files for a test that may even be the same as that from 571df676 - please rewrite using the existing schema and delete the rest diff --git a/t/prefetch/bugs.t b/t/prefetch/bugs.t deleted file mode 100644 index 0e7f9e1..0000000 --- a/t/prefetch/bugs.t +++ /dev/null @@ -1,29 +0,0 @@ -use warnings; -use strict; - -use Test::More; - -use lib qw(t/lib); -use DBICTest; - -my $schema = DBICTest->init_schema( - no_populate => 1, -); - -$schema->resultset('CD')->create({ - cdid => 0, - artist => { - artistid => 0, - name => 0, - rank => 0, - charfield => 0, - }, - title => 0, - year => 0, - genreid => 0, - single_track => 0, -}); - -ok( $schema->resultset('CD')->search( {}, { prefetch => 'artist' })->first->artist, 'artist loads even if all columns are 0'); - -done_testing; diff --git a/t/prefetch/false_colvalues.t b/t/prefetch/false_colvalues.t new file mode 100644 index 0000000..b3b2ef6 --- /dev/null +++ b/t/prefetch/false_colvalues.t @@ -0,0 +1,64 @@ +use warnings; +use strict; + +use Test::More; + +use lib qw(t/lib); +use DBICTest; + +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; + +is_deeply + { $cd->get_columns }, + { + artist => 0, + cdid => 0, + genreid => 0, + single_track => 0, + title => '', + year => 0, + }, + 'Expected CD columns present', +; + +is_deeply + { $cd->artist->get_columns }, + { + artistid => 0, + charfield => 0, + name => "", + rank => 0, + }, + 'Expected Artist columns present', +; + +is $queries, 1, 'Only one query fired - prefetch worked'; + +$schema->storage->debugcb(undef); +$schema->storage->debug($orig_debug); + +done_testing;