Resolve $rsrc instance duality on metadata traversal
[dbsrgits/DBIx-Class.git] / t / 86might_have.t
index 0ca9a06..62655e0 100644 (file)
@@ -1,43 +1,36 @@
+BEGIN { do "./t/lib/ANFANG.pm" or die ( $@ || $! ) }
+
 use strict;
 use warnings;
 
 use Test::More;
 use Test::Warn;
-use lib qw(t/lib);
+
 use DBICTest;
 
 my $schema = DBICTest->init_schema();
 
-my $queries;
-$schema->storage->debugcb( sub{ $queries++ } );
-my $sdebug = $schema->storage->debug;
-
 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($sdebug);
-
+$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->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};
@@ -62,5 +55,4 @@ warning_like {
   'Setting DBIC_DONT_VALIDATE_RELS suppresses nullable relation warnings';
 }
 
-$schema->storage->debug($sdebug);
 done_testing();