1 BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
12 my $schema = DBICTest->init_schema();
14 my $art = $schema->resultset("Artist")->find(4);
15 ok(!defined($art), 'Find on primary id: artist not found');
16 my @cd = $schema->resultset("CD")->find(6);
17 cmp_ok(@cd, '==', 1, 'Return something even in array context');
18 ok(@cd && !defined($cd[0]), 'Array contains an undef as only element');
20 $art = $schema->resultset("Artist")->find({artistid => '4'});
21 ok(!defined($art), 'Find on unique constraint: artist not found');
22 @cd = $schema->resultset("CD")->find({artist => '2', title => 'Lada-Di Lada-Da'});
23 cmp_ok(@cd, '==', 1, 'Return something even in array context');
24 ok(@cd && !defined($cd[0]), 'Array contains an undef as only element');
26 $art = $schema->resultset("Artist")->search({name => 'The Jesus And Mary Chain'});
27 isa_ok($art, 'DBIx::Class::ResultSet', 'get a DBIx::Class::ResultSet object');
28 my $next = $art->next;
29 ok(!defined($next), 'Nothing next in ResultSet');
30 my $cd = $schema->resultset("CD")->search({title => 'Rubbersoul'});
32 cmp_ok(@cd, '==', 1, 'Return something even in array context');
33 ok(@cd && !defined($cd[0]), 'Array contains an undef as only element');
35 $art = $schema->resultset("Artist")->single({name => 'Bikini Bottom Boys'});
36 ok(!defined($art), 'Find on primary id: artist not found');
37 @cd = $schema->resultset("CD")->single({title => 'The Singles 1962-2006'});
38 cmp_ok(@cd, '==', 1, 'Return something even in array context');
39 ok(@cd && !defined($cd[0]), 'Array contains an undef as only element');
41 $art = $schema->resultset("Artist")->search({name => 'Random Girl Band'});
42 isa_ok($art, 'DBIx::Class::ResultSet', 'get a DBIx::Class::ResultSet object');
44 ok(!defined($next), 'Nothing next in ResultSet');
45 $cd = $schema->resultset("CD")->search({title => 'Call of the West'});
47 cmp_ok(@cd, '==', 1, 'Return something even in array context');
48 ok(@cd && !defined($cd[0]), 'Array contains an undef as only element');
50 $cd = $schema->resultset("CD")->first;
51 my $artist_rs = $schema->resultset("Artist")->search({ artistid => $cd->artist->artistid });
52 for my $key ('', 'primary') {
53 my $art = $artist_rs->find({ name => 'some other name' }, { $key ? (key => $key) : () });
54 is($art->artistid, $cd->get_column('artist'), "Artist found through @{[ $key ? 'explicit' : 'implicit' ]} key locked in the resultset");
57 # collapsing and non-collapsing are separate codepaths, thus the separate tests
59 $schema->exception_action(sub {
64 $artist_rs = $schema->resultset("Artist");
68 } qr/\QQuery returned more than one row. SQL that returns multiple rows is DEPRECATED for ->find and ->single/
69 => "Non-unique find generated a cursor inexhaustion warning";
72 $artist_rs->find({}, { key => 'primary' })
73 } qr/Unable to satisfy requested constraint 'primary'/;
76 local $ENV{DBIC_NULLABLE_KEY_NOWARN};
79 $artist_rs->find({ artistid => undef }, { key => 'primary' })
82 qr/undef values supplied for requested unique constraint.+almost certainly not what you wanted/,
84 'One warning on NULL conditions for constraint'
88 is( $ea_count, 1, "exception action invoked the expected amount of times (just the exception)" );
90 $schema->exception_action(undef);
93 $artist_rs = $schema->resultset("Artist")->search({}, { prefetch => 'cds' });
97 } qr/\QDBIx::Class::ResultSet::find(): Query returned more than one row/, "Non-unique find generated a cursor inexhaustion warning";
100 $artist_rs->find({}, { key => 'primary' })
101 } qr/Unable to satisfy requested constraint 'primary'/;