Bring out the big-paranoia-harness - make describe_env infallible
[dbsrgits/DBIx-Class.git] / t / resultset / misled_rowparser.t
1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
2
3 use strict;
4 use warnings;
5
6 use Test::More;
7 use Test::Exception;
8
9 use DBICTest;
10 my $schema = DBICTest->init_schema();
11
12 # The nullchecks metadata for this collapse resolution is:
13 #
14 # mandatory => { 0 => 1 }
15 # from_first_encounter => [ [ 1, 2, 3 ] ]
16 # all_or_nothing => [ { 1 => 1, 2 => 1 } ]
17 #
18 my $rs = $schema->resultset('Artist')->search({}, {
19   collapse => 1,
20   join => { cds => 'tracks' },
21   columns => [qw(
22     me.artistid
23     cds.artist
24     cds.title
25   ),
26   { 'cds.tracks.title' => 'tracks.title' },
27   ],
28 });
29
30 my @cases = (
31   "'artistid'"
32     => [ undef, 0, 0, undef ],
33
34   "'artistid', 'cds.title'"
35     => [ undef, 0, undef, undef ],
36
37   "'artistid', 'cds.artist'"
38     => [ undef, undef, 0, undef ],
39
40   "'cds.artist'"
41     => [ 0, undef, 0, 0 ],
42
43   "'cds.title'"
44     => [ 0, 0, undef, 0 ],
45
46   # petrhaps need to report cds.title here as well, but that'll complicate checks even more...
47   "'cds.artist'"
48     => [ 0, undef, undef, 0 ],
49 );
50
51 while (@cases) {
52   my ($err, $cursor) = splice @cases, 0, 2;
53
54   $rs->{_stashed_rows} = [ $cursor ];
55
56   throws_ok
57     { $rs->next }
58     qr/\Qthe following columns are declared (or defaulted to) non-nullable within DBIC but NULLs were retrieved from storage: $err within data row/,
59     "Correct exception on non-nullable-yet-NULL $err"
60   ;
61 }
62
63 done_testing;