From: Peter Rabbitson Date: Wed, 1 Jul 2009 10:54:03 +0000 (+0000) Subject: Extend test X-Git-Tag: v0.08108~18^2~3 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=951b75814d2bd16a3f684145a7caf7777bc9abf4;p=dbsrgits%2FDBIx-Class.git Extend test --- diff --git a/t/prefetch/unresolvable.t b/t/prefetch/incomplete.t similarity index 59% rename from t/prefetch/unresolvable.t rename to t/prefetch/incomplete.t index a750291..a93e693 100644 --- a/t/prefetch/unresolvable.t +++ b/t/prefetch/incomplete.t @@ -6,18 +6,13 @@ use Test::Exception; use lib qw(t/lib); use DBICTest; -plan tests => 5; +plan tests => 9; my $schema = DBICTest->init_schema(); lives_ok(sub { - -# use Data::Dumper; -# warn Dumper [$schema->resultset('Artist')->search ({}, { prefetch => 'cds' })->hri_dump->all]; - - # while cds.* will be selected anyway (prefetch currently forces the result of _resolve_prefetch) - # only the requested me.name column will be fetched. This somehow does work on 08010 (tested) + # only the requested me.name column will be fetched. # reference sql with select => [...] # SELECT me.name, cds.title, cds.cdid, cds.artist, cds.title, cds.year, cds.genreid, cds.single_track FROM ... @@ -27,7 +22,7 @@ lives_ok(sub { { prefetch => [ qw/ cds / ], order_by => [ { -desc => 'me.name' }, 'cds.title' ], - select => [ qw/ me.name cds.title / ], + select => [qw/ me.name cds.title / ], } ); @@ -36,5 +31,23 @@ lives_ok(sub { is ($we_are_goth->name, 'We Are Goth', 'Correct first artist'); is ($we_are_goth->cds->count, 1, 'Correct number of CDs for first artist'); is ($we_are_goth->cds->first->title, 'Come Be Depressed With Us', 'Correct cd for artist'); +}, 'explicit prefetch on a keyless object works'); + + +lives_ok(sub { + # test implicit prefetch as well + + my $rs = $schema->resultset('CD')->search( + { title => 'Generic Manufactured Singles' }, + { + join=> 'artist', + select => [qw/ me.title artist.name / ], + } + ); + + my $cd = $rs->next; + is ($cd->title, 'Generic Manufactured Singles', 'CD title prefetched correctly'); + isa_ok ($cd->artist, 'DBICTest::Artist'); + is ($cd->artist->name, 'Random Boy Band', 'Artist object has correct name'); -}); +}, 'implicit keyless prefetch works');