45 changes: 32 additions & 13 deletions t/inflate/hri_torture.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use strict;
use warnings;

use Test::More;
use Test::Deep;
use lib qw(t/lib);
use DBICTest;

Expand Down Expand Up @@ -48,17 +49,33 @@ for (1,2) {
$schema->resultset('CD')->create({ artist => 1, year => 1977, title => "fuzzy_$_" });
}

my $rs = $schema->resultset('CD');
{
package DBICTest::HRI::Subclass;
use base 'DBIx::Class::ResultClass::HashRefInflator';
}

{
package DBICTest::HRI::Around;
use base 'DBIx::Class::ResultClass::HashRefInflator';

sub inflate_result { shift->next::method(@_) }
}

is_deeply
$rs->search({}, {
for my $rs (
$schema->resultset('CD')->search_rs({}, { result_class => 'DBIx::Class::ResultClass::HashRefInflator' }),
$schema->resultset('CD')->search_rs({}, { result_class => 'DBICTest::HRI::Subclass' }),
$schema->resultset('CD')->search_rs({}, { result_class => 'DBICTest::HRI::Around' }),
) {

cmp_deeply
[ $rs->search({}, {
columns => {
year => 'me.year',
'single_track.cd.artist.name' => 'artist.name',
},
join => { single_track => { cd => 'artist' } },
order_by => [qw/me.cdid artist.artistid/],
})->all_hri,
})->all ],
[
{
single_track => undef,
Expand Down Expand Up @@ -87,11 +104,11 @@ is_deeply
year => 1977
},
],
'plain 1:1 descending chain'
'plain 1:1 descending chain ' . $rs->result_class
;

is_deeply
$rs->search({}, {
cmp_deeply
[ $rs->search({}, {
columns => {
'artist' => 'me.artist',
'title' => 'me.title',
Expand All @@ -102,7 +119,7 @@ is_deeply
},
join => { single_track => { cd => { artist => { cds => 'tracks' } } } },
order_by => [qw/me.cdid artist.artistid cds.cdid tracks.trackid/],
})->all_hri,
})->all ],
[
{
artist => 1,
Expand Down Expand Up @@ -323,11 +340,11 @@ is_deeply
year => 1977
}
],
'non-collapsing 1:1:1:M:M chain',
'non-collapsing 1:1:1:M:M chain ' . $rs->result_class,
;

is_deeply
$rs->search({}, {
cmp_deeply
[ $rs->search({}, {
columns => {
'artist' => 'me.artist',
'title' => 'me.title',
Expand All @@ -339,7 +356,7 @@ is_deeply
join => { single_track => { cd => { artist => { cds => 'tracks' } } } },
order_by => [qw/me.cdid artist.artistid cds.cdid tracks.trackid/],
collapse => {}, #hashref to keep older DBIC versions happy (doesn't actually work)
})->all_hri,
})->all ],
[
{
artist => 1,
Expand Down Expand Up @@ -430,7 +447,9 @@ is_deeply
year => 1977
}
],
'collapsing 1:1:1:M:M chain',
'collapsing 1:1:1:M:M chain ' . $rs->result_class,
;

}

done_testing;
3 changes: 2 additions & 1 deletion t/prefetch/correlated.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use strict;
use warnings;

use Test::More;
use Test::Deep;
use lib qw(t/lib);
use DBICTest;
use DBIC::SqlMakerTest;
Expand Down Expand Up @@ -66,7 +67,7 @@ my $queries = 0;
$schema->storage->debugcb(sub { $queries++; });
$schema->storage->debug(1);

is_deeply (
cmp_deeply (
{ map
{ $_->cdid => {
track_titles => [ map { $_->title } ($_->tracks->all) ],
Expand Down
5 changes: 3 additions & 2 deletions t/prefetch/false_colvalues.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use warnings;
use strict;

use Test::More;
use Test::Deep;

use lib qw(t/lib);
use DBICTest;
Expand Down Expand Up @@ -32,7 +33,7 @@ $schema->storage->debug(1);

my $cd = $schema->resultset('CD')->search( {}, { prefetch => 'artist' })->next;

is_deeply
cmp_deeply
{ $cd->get_columns },
{
artist => 0,
Expand All @@ -45,7 +46,7 @@ is_deeply
'Expected CD columns present',
;

is_deeply
cmp_deeply
{ $cd->artist->get_columns },
{
artistid => 0,
Expand Down
7 changes: 4 additions & 3 deletions t/prefetch/incomplete.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use strict;
use warnings;

use Test::More;
use Test::Deep;
use Test::Exception;
use lib qw(t/lib);
use DBICTest;
Expand Down Expand Up @@ -41,7 +42,7 @@ lives_ok ( sub {
);
my $years = [qw/ 2001 2001 1999 1998 1997/];

is_deeply (
cmp_deeply (
[ $rs->search->get_column('me.year')->all ],
$years,
'Expected years (at least one duplicate)',
Expand All @@ -67,13 +68,13 @@ lives_ok ( sub {
push @pref_cds_and_tracks, $data;
}

is_deeply (
cmp_deeply (
\@pref_cds_and_tracks,
\@cds_and_tracks,
'Correct collapsing on non-unique primary object'
);

is_deeply (
cmp_deeply (
[ $pref_rs->search ({}, { result_class => 'DBIx::Class::ResultClass::HashRefInflator' })->all ],
\@cds_and_tracks,
'Correct HRI collapsing on non-unique primary object'
Expand Down
9 changes: 5 additions & 4 deletions t/prefetch/manual.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use strict;
use warnings;

use Test::More;
use Test::Deep;
use Test::Exception;
use lib qw(t/lib);
use DBICTest;
Expand Down Expand Up @@ -64,7 +65,7 @@ my $rs = $schema->resultset ('CD')->search ({}, {

my $hri_rs = $rs->search({}, { result_class => 'DBIx::Class::ResultClass::HashRefInflator' });

is_deeply (
cmp_deeply (
[$hri_rs->all],
[
{
Expand Down Expand Up @@ -189,7 +190,7 @@ TODO: {
local $TODO = 'Something is wrong with filter type rels, they throw on incomplete objects >.<';

lives_ok {
is_deeply (
cmp_deeply (
{ $row->single_track->get_columns },
{},
'empty intermediate object ok',
Expand Down Expand Up @@ -310,13 +311,13 @@ $schema->storage->debugcb(undef);
$schema->storage->debug($orig_debug);
is ($queries, 2, "Only two queries for rwo prefetch calls total");

# can't is_deeply a random set - need *some* order
# can't cmp_deeply a random set - need *some* order
my @hris = sort { $a->{year} cmp $b->{year} } @{$rs->search({}, {
order_by => [ 'tracks_2.title', 'tracks.title', 'cds.cdid', \ 'RANDOM()' ],
})->all_hri};
is (@hris, 6, 'hri count matches' );

is_deeply (\@hris, [
cmp_deeply (\@hris, [
{
single_track => undef,
tracks => [
Expand Down
3 changes: 2 additions & 1 deletion t/prefetch/multiple_hasmany_torture.t
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use strict;
use warnings;

use Test::More;
use Test::Deep;
use Test::Exception;
use lib qw(t/lib);
use DBICTest;
Expand Down Expand Up @@ -91,7 +92,7 @@ my $mo = $mo_rs->next;

is( @{$mo->{cds}}, 2, 'two CDs' );

is_deeply(
cmp_deeply(
$mo,
{
'cds' => [
Expand Down
379 changes: 58 additions & 321 deletions t/resultset/inflate_result_api.t

Large diffs are not rendered by default.

227 changes: 126 additions & 101 deletions t/resultset/rowparser_internals.t

Large diffs are not rendered by default.