X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fprefetch%2Fcount.t;h=8fb2442a5ae29fb6773099478af86d21713fb080;hb=49eeb48de3d8ff685926b595fa0f3f5e680eaee2;hp=4311e808090529dc3676836d3eb241530820c05c;hpb=2cfc22ddff9cb35524031dfc9d429d294b5e3d6e;p=dbsrgits%2FDBIx-Class-Historic.git diff --git a/t/prefetch/count.t b/t/prefetch/count.t index 4311e80..8fb2442 100644 --- a/t/prefetch/count.t +++ b/t/prefetch/count.t @@ -6,8 +6,6 @@ use lib qw(t/lib); use DBICTest; use DBIC::SqlMakerTest; -plan tests => 23; - my $schema = DBICTest->init_schema(); my $cd_rs = $schema->resultset('CD')->search ( @@ -15,7 +13,6 @@ my $cd_rs = $schema->resultset('CD')->search ( { prefetch => ['tracks', 'artist'] }, ); - is($cd_rs->count, 5, 'CDs with tracks count'); is($cd_rs->search_related('tracks')->count, 15, 'Tracks associated with CDs count (before SELECT()ing)'); @@ -77,26 +74,23 @@ is_same_sql_bind ( => 4 ] ], ); - { local $TODO = "Chaining with prefetch is fundamentally broken"; + $schema->is_executed_querycount( sub { - my $queries; - $schema->storage->debugcb ( sub { $queries++ } ); - $schema->storage->debug (1); - - my $cds = $cd2->search_related ('artist', {}, { prefetch => { cds => 'tracks' }, join => 'twokeys' }) + my $cds = $cd2->search_related ('artist', {}, { prefetch => { cds => 'tracks' }, join => 'twokeys' }) ->search_related ('cds'); - my $tracks = $cds->search_related ('tracks'); - - is($tracks->count, 2, "2 Tracks counted on cd via artist via one of the cds"); - is(scalar($tracks->all), 2, "2 Tracks prefetched on cd via artist via one of the cds"); - is($tracks->count, 2, "Cached 2 Tracks counted on cd via artist via one of the cds"); + my $tracks = $cds->search_related ('tracks'); - is($cds->count, 2, "2 CDs counted on artist via one of the cds"); - is(scalar($cds->all), 2, "2 CDs prefetched on artist via one of the cds"); - is($cds->count, 2, "Cached 2 CDs counted on artist via one of the cds"); + is($tracks->count, 2, "2 Tracks counted on cd via artist via one of the cds"); + is(scalar($tracks->all), 2, "2 Tracks prefetched on cd via artist via one of the cds"); + is($tracks->count, 2, "Cached 2 Tracks counted on cd via artist via one of the cds"); - is ($queries, 3, '2 counts + 1 prefetch?'); + is($cds->count, 2, "2 CDs counted on artist via one of the cds"); + is(scalar($cds->all), 2, "2 CDs prefetched on artist via one of the cds"); + is($cds->count, 2, "Cached 2 CDs counted on artist via one of the cds"); + }, 3, '2 counts + 1 prefetch?' ); } + +done_testing;