new config option to DBICTest to let you set an alternative storage type, start on...
[dbsrgits/DBIx-Class.git] / t / 84serialize.t
index 51c7e56..76e18c2 100644 (file)
@@ -9,8 +9,15 @@ use Storable qw(dclone freeze thaw);
 my $schema = DBICTest->init_schema();
 
 my %stores = (
-    dclone          => sub { return dclone($_[0]) },
-    "freeze/thaw"   => sub { return thaw(freeze($_[0])) },
+    dclone_method           => sub { return $schema->dclone($_[0]) },
+    dclone_func             => sub { return dclone($_[0]) },
+    "freeze/thaw_method"    => sub {
+        my $ice = $schema->freeze($_[0]);
+        return $schema->thaw($ice);
+    },
+    "freeze/thaw_func"      => sub {
+        thaw(freeze($_[0]));
+    },
 );
 
 plan tests => (7 * keys %stores);
@@ -19,11 +26,25 @@ for my $name (keys %stores) {
     my $store = $stores{$name};
 
     my $artist = $schema->resultset('Artist')->find(1);
+    
+    # Test that the procedural versions will work if there's a registered
+    # schema as with CDBICompat objects and that the methods work
+    # without.
+    if( $name =~ /func/ ) {
+        $artist->result_source_instance->schema($schema);
+        DBICTest::CD->result_source_instance->schema($schema);
+    }
+    else {
+        $artist->result_source_instance->schema(undef);
+        DBICTest::CD->result_source_instance->schema(undef);
+    }
+
     my $copy = eval { $store->($artist) };
     is_deeply($copy, $artist, "serialize row object works: $name");
 
     # Test that an object with a related_resultset can be serialized.
     my @cds = $artist->related_resultset("cds");
+
     ok $artist->{related_resultsets}, 'has key: related_resultsets';
 
     $copy = eval { $store->($artist) };
@@ -34,6 +55,6 @@ for my $name (keys %stores) {
                   qq[serialize with related_resultset "$key"]);
     }
   
-    ok eval { $copy->discard_changes; 1 };
+    ok eval { $copy->discard_changes; 1 } or diag $@;
     is($copy->id, $artist->id, "IDs still match ");
 }