X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fresultset%2Fmisled_rowparser.t;fp=t%2Fresultset%2Fmisled_rowparser.t;h=2c76aeda1a87dc090d391b24ad0200136cfea9e9;hb=b3a400a044a5e4a768e26d450e3cce289481ee7a;hp=0000000000000000000000000000000000000000;hpb=5ff6d6034ddcb696d24c4b716b5c12f109004d1f;p=dbsrgits%2FDBIx-Class.git diff --git a/t/resultset/misled_rowparser.t b/t/resultset/misled_rowparser.t new file mode 100644 index 0000000..2c76aed --- /dev/null +++ b/t/resultset/misled_rowparser.t @@ -0,0 +1,63 @@ +BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) } + +use strict; +use warnings; + +use Test::More; +use Test::Exception; + +use DBICTest; +my $schema = DBICTest->init_schema(); + +# The nullchecks metadata for this collapse resolution is: +# +# mandatory => { 0 => 1 } +# from_first_encounter => [ [ 1, 2, 3 ] ] +# all_or_nothing => [ { 1 => 1, 2 => 1 } ] +# +my $rs = $schema->resultset('Artist')->search({}, { + collapse => 1, + join => { cds => 'tracks' }, + columns => [qw( + me.artistid + cds.artist + cds.title + ), + { 'cds.tracks.title' => 'tracks.title' }, + ], +}); + +my @cases = ( + "'artistid'" + => [ undef, 0, 0, undef ], + + "'artistid', 'cds.title'" + => [ undef, 0, undef, undef ], + + "'artistid', 'cds.artist'" + => [ undef, undef, 0, undef ], + + "'cds.artist'" + => [ 0, undef, 0, 0 ], + + "'cds.title'" + => [ 0, 0, undef, 0 ], + + # petrhaps need to report cds.title here as well, but that'll complicate checks even more... + "'cds.artist'" + => [ 0, undef, undef, 0 ], +); + +while (@cases) { + my ($err, $cursor) = splice @cases, 0, 2; + + $rs->{_stashed_rows} = [ $cursor ]; + + throws_ok + { $rs->next } + qr/\Qthe following columns are declared (or defaulted to) non-nullable within DBIC but NULLs were retrieved from storage: $err within data row/, + "Correct exception on non-nullable-yet-NULL $err" + ; +} + +done_testing;