X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2F86might_have.t;h=f656802f4aa6f461748186fa8aac07563864e671;hb=b83736a7d3235d2f50fe5695550eb3637432d960;hp=1d4af788fe56780291cfe7ae86addd81e1c194c8;hpb=d6915f449e2d68ac184d6bc616043fd605913757;p=dbsrgits%2FDBIx-Class.git diff --git a/t/86might_have.t b/t/86might_have.t index 1d4af78..f656802 100644 --- a/t/86might_have.t +++ b/t/86might_have.t @@ -1,47 +1,58 @@ +BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) } + use strict; -use warnings; +use warnings; use Test::More; -use lib qw(t/lib); -use DBICTest; - -my $schema = DBICTest::init_schema(); - -my $queries; -#$schema->storage->debugfh(IO::File->new('t/var/temp.trace', 'w')); -$schema->storage->debugcb( sub{ $queries++ } ); +use Test::Warn; -eval "use DBD::SQLite"; -plan skip_all => 'needs DBD::SQLite for testing' if $@; -plan tests => 2; +use DBICTest; +my $schema = DBICTest->init_schema(); my $cd = $schema->resultset("CD")->find(1); $cd->title('test'); -# SELECT count -$queries = 0; -$schema->storage->debug(1); - -$cd->update; - -is($queries, 1, 'liner_notes (might_have) not prefetched - do not load -liner_notes on update'); - -$schema->storage->debug(0); - +$schema->is_executed_querycount( sub { + $cd->update; +}, { + BEGIN => 1, + UPDATE => 1, + COMMIT => 1, +}, 'liner_notes (might_have) not prefetched - do not load liner_notes on update' ); my $cd2 = $schema->resultset("CD")->find(2, {prefetch => 'liner_notes'}); $cd2->title('test2'); -# SELECT count -$queries = 0; -$schema->storage->debug(1); - -$cd2->update; - -is($queries, 1, 'liner_notes (might_have) prefetched - do not load -liner_notes on update'); - -$schema->storage->debug(0); - +$schema->is_executed_querycount( sub { + $cd2->update; +}, { + BEGIN => 1, + UPDATE => 1, + COMMIT => 1, +}, 'liner_notes (might_have) prefetched - do not load liner_notes on update'); + +warning_like { + local $ENV{DBIC_DONT_VALIDATE_RELS}; + + DBICTest::Schema::Bookmark->might_have( + linky => 'DBICTest::Schema::Link', + { "foreign.id" => "self.link" }, + ); +} + qr{'might_have'/'has_one' must not be used on columns with is_nullable set to true}, + 'might_have should warn if the self.id column is nullable'; + +{ + local $ENV{DBIC_DONT_VALIDATE_RELS} = 1; + warning_is { + DBICTest::Schema::Bookmark->might_have( + slinky => 'DBICTest::Schema::Link', + { "foreign.id" => "self.link" }, + ); + } + undef, + 'Setting DBIC_DONT_VALIDATE_RELS suppresses nullable relation warnings'; +} + +done_testing();