[Bast-commits] r5446 - DBIx-Class/0.08/trunk/t

ribasushi at dev.catalyst.perl.org ribasushi at dev.catalyst.perl.org
Wed Feb 11 08:25:00 GMT 2009


Author: ribasushi
Date: 2009-02-11 08:24:58 +0000 (Wed, 11 Feb 2009)
New Revision: 5446

Modified:
   DBIx-Class/0.08/trunk/t/77prefetch.t
Log:
Test for resultset corruption by search()

Modified: DBIx-Class/0.08/trunk/t/77prefetch.t
===================================================================
--- DBIx-Class/0.08/trunk/t/77prefetch.t	2009-02-10 22:53:48 UTC (rev 5445)
+++ DBIx-Class/0.08/trunk/t/77prefetch.t	2009-02-11 08:24:58 UTC (rev 5446)
@@ -2,6 +2,7 @@
 use warnings;  
 
 use Test::More;
+use Test::Exception;
 use lib qw(t/lib);
 use DBICTest;
 use Data::Dumper;
@@ -16,7 +17,7 @@
     eval "use DBD::SQLite";
     plan $@
         ? ( skip_all => 'needs DBD::SQLite for testing' )
-        : ( tests => 58 );
+        : ( tests => 63 );
 }
 
 # figure out if we've got a version of sqlite that is older than 3.2.6, in
@@ -45,6 +46,27 @@
 is(Dumper($attr), $attr_str, 'Attribute hash untouched after search()');
 cmp_ok($rs + 0, '==', 3, 'Correct number of records returned');
 
+# A search() with prefetch seems to pollute an already joined resultset
+# in a way that offsets future joins (adapted from a test case by Debolaz)
+{
+  my $cd_rs = $schema->resultset ('Producer')->first->cds;
+  my $attrs = Dumper $cd_rs->{attrs};
+
+  $cd_rs->search ({})->all;
+  is (Dumper ($cd_rs->{attrs}), $attrs, 'Resultset attributes preserved after a simple search');
+
+  lives_ok (sub {
+    $cd_rs->search ({'artist.artistid' => 1}, { prefetch => 'artist' })->all;
+    is (Dumper ($cd_rs->{attrs}), $attrs, 'Resultset attributes preserved after search with prefetch');
+  }, 'first prefetching search ok');
+
+  lives_ok (sub {
+    $cd_rs->search ({'artist.artistid' => 1}, { prefetch => 'artist' })->all;
+    is (Dumper ($cd_rs->{attrs}), $attrs, 'Resultset attributes preserved after another search with prefetch')
+  }, 'second prefetching search ok');
+}
+
+
 my $queries = 0;
 $schema->storage->debugcb(sub { $queries++; });
 $schema->storage->debug(1);




More information about the Bast-commits mailing list