From: Peter Rabbitson Date: Mon, 1 Mar 2010 00:13:51 +0000 (+0000) Subject: Sketches of tests that should ultimately pass X-Git-Tag: v0.08240~33 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=69ab63d48af1134c7a6b35ae9005b448a0e37d9e;p=dbsrgits%2FDBIx-Class.git Sketches of tests that should ultimately pass --- diff --git a/t/prefetch/incomplete.t b/t/prefetch/incomplete.t index a93e693..000a386 100644 --- a/t/prefetch/incomplete.t +++ b/t/prefetch/incomplete.t @@ -23,7 +23,7 @@ lives_ok(sub { prefetch => [ qw/ cds / ], order_by => [ { -desc => 'me.name' }, 'cds.title' ], select => [qw/ me.name cds.title / ], - } + }, ); is ($rs->count, 2, 'Correct number of collapsed artists'); @@ -34,6 +34,57 @@ lives_ok(sub { }, 'explicit prefetch on a keyless object works'); +lives_ok ( sub { + + my $rs = $schema->resultset('CD')->search( + {}, + { + order_by => [ { -desc => 'me.year' } ], + } + ); + my $years = [qw/ 2001 2001 1999 1998 1997/]; + + is_deeply ( + [ $rs->search->get_column('me.year')->all ], + $years, + 'Expected years (at least one duplicate)', + ); + + my @cds_and_tracks; + for my $cd ($rs->all) { + my $data->{year} = $cd->year; + for my $tr ($cd->tracks->all) { + push @{$data->{tracks}}, { $tr->get_columns }; + } + push @cds_and_tracks, $data; + } + + my $pref_rs = $rs->search ({}, { columns => ['year'], prefetch => 'tracks' }); + + my @pref_cds_and_tracks; + for my $cd ($pref_rs->all) { + my $data = { $cd->get_columns }; + for my $tr ($cd->tracks->all) { + push @{$data->{tracks}}, { $tr->get_columns }; + } + push @pref_cds_and_tracks, $data; + } + + is_deeply ( + \@pref_cds_and_tracks, + \@cds_and_tracks, + 'Correct collapsing on non-unique primary object' + ); + + is_deeply ( + [ $pref_rs->search ({}, { result_class => 'DBIx::Class::ResultClass::HashRefInflator' })->all ], + \@cds_and_tracks, + 'Correct HRI collapsing on non-unique primary object' + ); + +}, 'weird collapse lives'); + + lives_ok(sub { # test implicit prefetch as well diff --git a/t/prefetch/manual.t b/t/prefetch/manual.t new file mode 100644 index 0000000..75b117e --- /dev/null +++ b/t/prefetch/manual.t @@ -0,0 +1,31 @@ +use strict; +use warnings; + +use Test::More; +use Test::Exception; +use lib qw(t/lib); +use DBICTest; + +my $schema = DBICTest->init_schema(); + +my $rs = $schema->resultset ('CD')->search ({}, { + join => [ 'tracks', { single_track => { cd => { artist => { cds => 'tracks' } } } } ], + collapse => 1, + columns => [ + { 'year' => 'me.year' }, # non-unique + { 'genreid' => 'me.genreid' }, # nullable + { 'tracks.title' => 'tracks.title' }, # non-unique (no me.id) + { 'single_track.cd.artist.cds.cdid' => 'cds.cdid' }, # to give uniquiness to ...tracks.title below + { 'single_track.cd.artist.cds.artist' => 'cds.artist' }, # non-unique + { 'single_track.cd.artist.cds.year' => 'cds.year' }, # non-unique + { 'single_track.cd.artist.cds.genreid' => 'cds.genreid' }, # nullable + { 'single_track.cd.artist.cds.tracks.title' => 'tracks_2.title' }, # unique when combined with ...cds.cdid above + { 'latest_cd' => { max => 'cds.year' } }, # random function + ], + result_class => 'DBIx::Class::ResultClass::HashRefInflator', +}); + +use Data::Dumper::Concise; +die Dumper [$rs->all]; + +