X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F61findnot.t;h=e9fe1ac755a20477a8746e8f03dae04f6eb1dcd9;hb=4c0829325108ab553f442e1553469db9d6ef5851;hp=d7dde4db5a881f96a44d32ba28f7792e15bb35ed;hpb=65c1217de6381d5cc8ffb10cd6bb870144a2649b;p=dbsrgits%2FDBIx-Class.git diff --git a/t/61findnot.t b/t/61findnot.t index d7dde4d..e9fe1ac 100644 --- a/t/61findnot.t +++ b/t/61findnot.t @@ -1,10 +1,12 @@ +BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) } + use strict; use warnings; use Test::More; use Test::Warn; use Test::Exception; -use lib qw(t/lib); + use DBICTest; my $schema = DBICTest->init_schema(); @@ -47,17 +49,23 @@ ok(@cd && !defined($cd[0]), 'Array contains an undef as only element'); $cd = $schema->resultset("CD")->first; my $artist_rs = $schema->resultset("Artist")->search({ artistid => $cd->artist->artistid }); -$art = $artist_rs->find({ name => 'some other name' }, { key => 'primary' }); -ok($art, 'Artist found by key in the resultset'); +for my $key ('', 'primary') { + my $art = $artist_rs->find({ name => 'some other name' }, { $key ? (key => $key) : () }); + is($art->artistid, $cd->get_column('artist'), "Artist found through @{[ $key ? 'explicit' : 'implicit' ]} key locked in the resultset"); +} # collapsing and non-collapsing are separate codepaths, thus the separate tests - +my $ea_count = 0; +$schema->exception_action(sub { + $ea_count++; + die @_; +}); $artist_rs = $schema->resultset("Artist"); warnings_exist { $artist_rs->find({}) -} qr/\QDBIx::Class::ResultSet::find(): Query returned more than one row. SQL that returns multiple rows is DEPRECATED for ->find and ->single/ +} qr/\QQuery returned more than one row. SQL that returns multiple rows is DEPRECATED for ->find and ->single/ => "Non-unique find generated a cursor inexhaustion warning"; throws_ok { @@ -65,6 +73,7 @@ throws_ok { } qr/Unable to satisfy requested constraint 'primary'/; for (1, 0) { + local $ENV{DBIC_NULLABLE_KEY_NOWARN}; warnings_like sub { $artist_rs->find({ artistid => undef }, { key => 'primary' }) @@ -76,6 +85,10 @@ for (1, 0) { ; } +is( $ea_count, 1, "exception action invoked the expected amount of times (just the exception)" ); + +$schema->exception_action(undef); + $artist_rs = $schema->resultset("Artist")->search({}, { prefetch => 'cds' });