added a test for count() caching
[dbsrgits/DBIx-Class.git] / t / run / 23cache.tl
index 6548465..4afd2b2 100644 (file)
@@ -3,7 +3,7 @@ my $schema = shift;
 
 eval "use DBD::SQLite";
 plan skip_all => 'needs DBD::SQLite for testing' if $@;
-plan tests => 14;
+plan tests => 16;
 
 my $rs = $schema->resultset("Artist")->search(
   { artistid => 1 }
@@ -13,6 +13,16 @@ my $artist = $rs->first;
 
 is( scalar @{ $rs->get_cache }, 0, 'cache is not populated without cache attribute' );
 
+my @a = $schema->resultset("Artist")->search(
+  { },
+  {
+    join => [ qw/ cds /],
+    prefetch => [qw/ cds /],
+  }
+);
+
+is(scalar @a, 3, 'artist with cds: count parent objects');
+
 $rs = $schema->resultset("Artist")->search(
   { 'artistid' => 1 },
   {
@@ -73,6 +83,16 @@ $rs = $schema->resultset("Artist")->search(
     },
   }
 );
+{
+my $artist_count_before = $schema->resultset('Artist')->count;
+$schema->resultset("Artist")->create({artistid=>4,name=>qq{Humoungous Hamsters}});
+is($schema->resultset('Artist')->count, $artist_count_before + 1, 'count() reflects new artist');
+my $artist = $schema->resultset("Artist")->search(
+  { artistid => 4 },{prefetch=>[qw/cds/]}
+)->first;
+
+is($artist->cds, 0, 'No cds for this artist');
+}
 
 # SELECT count for nested has_many prefetch
 unlink 't/var/dbic.trace' if -e 't/var/dbic.trace';