X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F61findnot.t;h=d7dde4db5a881f96a44d32ba28f7792e15bb35ed;hb=992a24f640638601acb795c24af493d789368400;hp=17f64fd4ea073498d25fb5e67604436e37d8542e;hpb=550adccc763b6887aa2ce43b1d1d9fb48b240763;p=dbsrgits%2FDBIx-Class.git diff --git a/t/61findnot.t b/t/61findnot.t index 17f64fd..d7dde4d 100644 --- a/t/61findnot.t +++ b/t/61findnot.t @@ -1,15 +1,14 @@ use strict; -use warnings; +use warnings; use Test::More; use Test::Warn; +use Test::Exception; use lib qw(t/lib); use DBICTest; my $schema = DBICTest->init_schema(); -plan tests => 20; - my $art = $schema->resultset("Artist")->find(4); ok(!defined($art), 'Find on primary id: artist not found'); my @cd = $schema->resultset("CD")->find(6); @@ -51,12 +50,41 @@ my $artist_rs = $schema->resultset("Artist")->search({ artistid => $cd->artist-> $art = $artist_rs->find({ name => 'some other name' }, { key => 'primary' }); ok($art, 'Artist found by key in the resultset'); +# collapsing and non-collapsing are separate codepaths, thus the separate tests + + $artist_rs = $schema->resultset("Artist"); -warning_is { + +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/ + => "Non-unique find generated a cursor inexhaustion warning"; + +throws_ok { $artist_rs->find({}, { key => 'primary' }) -} "DBIx::Class::ResultSet::find(): Query returned more than one row", "Non-unique find generated a cursor inexhaustion warning"; +} qr/Unable to satisfy requested constraint 'primary'/; + +for (1, 0) { + warnings_like + sub { + $artist_rs->find({ artistid => undef }, { key => 'primary' }) + }, + $_ ? [ + qr/undef values supplied for requested unique constraint.+almost certainly not what you wanted/, + ] : [], + 'One warning on NULL conditions for constraint' + ; +} + $artist_rs = $schema->resultset("Artist")->search({}, { prefetch => 'cds' }); -warning_is { + +warnings_exist { + $artist_rs->find({}) +} qr/\QDBIx::Class::ResultSet::find(): Query returned more than one row/, "Non-unique find generated a cursor inexhaustion warning"; + +throws_ok { $artist_rs->find({}, { key => 'primary' }) -} "DBIx::Class::ResultSet::find(): Query returned more than one row", "Non-unique find generated a cursor inexhaustion warning"; +} qr/Unable to satisfy requested constraint 'primary'/; + +done_testing;