[Bast-commits] r6614 - in DBIx-Class/0.08/trunk/t: . inflate

ribasushi at dev.catalyst.perl.org ribasushi at dev.catalyst.perl.org
Thu Jun 11 12:29:49 GMT 2009


Author: ribasushi
Date: 2009-06-11 12:29:48 +0000 (Thu, 11 Jun 2009)
New Revision: 6614

Added:
   DBIx-Class/0.08/trunk/t/inflate/
   DBIx-Class/0.08/trunk/t/inflate/core.t
   DBIx-Class/0.08/trunk/t/inflate/hri.t
   DBIx-Class/0.08/trunk/t/inflate/serialize.t
Removed:
   DBIx-Class/0.08/trunk/t/68inflate.t
   DBIx-Class/0.08/trunk/t/68inflate_resultclass_hashrefinflator.t
   DBIx-Class/0.08/trunk/t/68inflate_serialize.t
Log:
Move around inflation tests

Deleted: DBIx-Class/0.08/trunk/t/68inflate.t
===================================================================
--- DBIx-Class/0.08/trunk/t/68inflate.t	2009-06-11 07:23:54 UTC (rev 6613)
+++ DBIx-Class/0.08/trunk/t/68inflate.t	2009-06-11 12:29:48 UTC (rev 6614)
@@ -1,112 +0,0 @@
-use strict;
-use warnings;  
-
-use Test::More;
-use lib qw(t/lib);
-use DBICTest;
-
-my $schema = DBICTest->init_schema();
-
-eval { require DateTime };
-plan skip_all => "Need DateTime for inflation tests" if $@;
-
-plan tests => 21;
-
-$schema->class('CD')
-#DBICTest::Schema::CD
-->inflate_column( 'year',
-    { inflate => sub { DateTime->new( year => shift ) },
-      deflate => sub { shift->year } }
-);
-Class::C3->reinitialize;
-
-# inflation test
-my $cd = $schema->resultset("CD")->find(3);
-
-is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' );
-
-is( $cd->year->year, 1997, 'inflated year ok' );
-
-is( $cd->year->month, 1, 'inflated month ok' );
-
-eval { $cd->year(\'year +1'); };
-ok(!$@, 'updated year using a scalarref');
-$cd->update();
-$cd->discard_changes();
-
-is( ref($cd->year), 'DateTime', 'year is still a DateTime, ok' );
-
-is( $cd->year->year, 1998, 'updated year, bypassing inflation' );
-
-is( $cd->year->month, 1, 'month is still 1' );  
-
-# get_inflated_column test
-
-is( ref($cd->get_inflated_column('year')), 'DateTime', 'get_inflated_column produces a DateTime');
-
-# deflate test
-my $now = DateTime->now;
-$cd->year( $now );
-$cd->update;
-
-$cd = $schema->resultset("CD")->find(3);
-is( $cd->year->year, $now->year, 'deflate ok' );
-
-# set_inflated_column test
-eval { $cd->set_inflated_column('year', $now) };
-ok(!$@, 'set_inflated_column with DateTime object');
-$cd->update;
-
-$cd = $schema->resultset("CD")->find(3);                 
-is( $cd->year->year, $now->year, 'deflate ok' );
-
-$cd = $schema->resultset("CD")->find(3);                 
-my $before_year = $cd->year->year;
-eval { $cd->set_inflated_column('year', \'year + 1') };
-ok(!$@, 'set_inflated_column to "year + 1"');
-$cd->update;
-
-$cd = $schema->resultset("CD")->find(3);                 
-is( $cd->year->year, $before_year+1, 'deflate ok' );
-
-# store_inflated_column test
-$cd = $schema->resultset("CD")->find(3);                 
-eval { $cd->store_inflated_column('year', $now) };
-ok(!$@, 'store_inflated_column with DateTime object');
-$cd->update;
-
-is( $cd->year->year, $now->year, 'deflate ok' );
-
-# update tests
-$cd = $schema->resultset("CD")->find(3);                 
-eval { $cd->update({'year' => $now}) };
-ok(!$@, 'update using DateTime object ok');
-is($cd->year->year, $now->year, 'deflate ok');
-
-$cd = $schema->resultset("CD")->find(3);                 
-$before_year = $cd->year->year;
-eval { $cd->update({'year' => \'year + 1'}) };
-ok(!$@, 'update using scalarref ok');
-
-$cd = $schema->resultset("CD")->find(3);                 
-is($cd->year->year, $before_year + 1, 'deflate ok');
-
-# discard_changes test
-$cd = $schema->resultset("CD")->find(3);                 
-# inflate the year
-$before_year = $cd->year->year;
-$cd->update({ year => \'year + 1'});
-$cd->discard_changes;
-
-is($cd->year->year, $before_year + 1, 'discard_changes clears the inflated value');
-
-my $copy = $cd->copy({ year => $now, title => "zemoose" });
-
-isnt( $copy->year->year, $before_year, "copy" );
- 
-# eval { $cd->store_inflated_column('year', \'year + 1') };
-# print STDERR "ERROR: $@" if($@);
-# ok(!$@, 'store_inflated_column to "year + 1"');
-
-# is_deeply( $cd->year, \'year + 1', 'deflate ok' );
-

Deleted: DBIx-Class/0.08/trunk/t/68inflate_resultclass_hashrefinflator.t
===================================================================
--- DBIx-Class/0.08/trunk/t/68inflate_resultclass_hashrefinflator.t	2009-06-11 07:23:54 UTC (rev 6613)
+++ DBIx-Class/0.08/trunk/t/68inflate_resultclass_hashrefinflator.t	2009-06-11 12:29:48 UTC (rev 6614)
@@ -1,126 +0,0 @@
-use strict;
-use warnings;  
-
-use Test::More qw(no_plan);
-use lib qw(t/lib);
-use DBICTest;
-my $schema = DBICTest->init_schema();
-
-
-# Under some versions of SQLite if the $rs is left hanging around it will lock
-# So we create a scope here cos I'm lazy
-{
-    my $rs = $schema->resultset('CD');
-
-    # get the defined columns
-    my @dbic_cols = sort $rs->result_source->columns;
-
-    # use the hashref inflator class as result class
-    $rs->result_class('DBIx::Class::ResultClass::HashRefInflator');
-
-    # fetch first record
-    my $datahashref1 = $rs->first;
-
-    my @hashref_cols = sort keys %$datahashref1;
-
-    is_deeply( \@dbic_cols, \@hashref_cols, 'returned columns' );
-}
-
-
-sub check_cols_of {
-    my ($dbic_obj, $datahashref) = @_;
-    
-    foreach my $col (keys %$datahashref) {
-        # plain column
-        if (not ref ($datahashref->{$col}) ) {
-            is ($datahashref->{$col}, $dbic_obj->get_column($col), 'same value');
-        }
-        # related table entry (belongs_to)
-        elsif (ref ($datahashref->{$col}) eq 'HASH') {
-            check_cols_of($dbic_obj->$col, $datahashref->{$col});
-        }
-        # multiple related entries (has_many)
-        elsif (ref ($datahashref->{$col}) eq 'ARRAY') {
-            my @dbic_reltable = $dbic_obj->$col;
-            my @hashref_reltable = @{$datahashref->{$col}};
-  
-            is (scalar @hashref_reltable, scalar @dbic_reltable, 'number of related entries');
-
-            # for my $index (0..scalar @hashref_reltable) {
-            for my $index (0..scalar @dbic_reltable) {
-                my $dbic_reltable_obj       = $dbic_reltable[$index];
-                my $hashref_reltable_entry  = $hashref_reltable[$index];
-                
-                check_cols_of($dbic_reltable_obj, $hashref_reltable_entry);
-            }
-        }
-    }
-}
-
-# create a cd without tracks for testing empty has_many relationship
-$schema->resultset('CD')->create({ title => 'Silence is golden', artist => 3, year => 2006 });
-
-# order_by to ensure both resultsets have the rows in the same order
-# also check result_class-as-an-attribute syntax
-my $rs_dbic = $schema->resultset('CD')->search(undef,
-    {
-        prefetch    => [ qw/ artist tracks / ],
-        order_by    => [ 'me.cdid', 'tracks.position' ],
-    }
-);
-my $rs_hashrefinf = $schema->resultset('CD')->search(undef,
-    {
-        prefetch    => [ qw/ artist tracks / ],
-        order_by    => [ 'me.cdid', 'tracks.position' ],
-        result_class => 'DBIx::Class::ResultClass::HashRefInflator',
-    }
-);
-
-my @dbic        = $rs_dbic->all;
-my @hashrefinf  = $rs_hashrefinf->all;
-
-for my $index (0 .. $#hashrefinf) {
-    my $dbic_obj    = $dbic[$index];
-    my $datahashref = $hashrefinf[$index];
-
-    check_cols_of($dbic_obj, $datahashref);
-}
-
-# sometimes for ultra-mega-speed you want to fetch columns in esoteric ways
-# check the inflator over a non-fetching join 
-$rs_dbic = $schema->resultset ('Artist')->search ({ 'me.artistid' => 1}, {
-    prefetch => { cds => 'tracks' },
-    order_by => [qw/cds.cdid tracks.trackid/],
-});
-
-$rs_hashrefinf = $schema->resultset ('Artist')->search ({ 'me.artistid' => 1}, {
-    join     => { cds => 'tracks' },
-    select   => [qw/name   tracks.title      tracks.cd       /],
-    as       => [qw/name   cds.tracks.title  cds.tracks.cd   /],
-    order_by => [qw/cds.cdid tracks.trackid/],
-    result_class => 'DBIx::Class::ResultClass::HashRefInflator',
-});
-
- at dbic = map { $_->tracks->all } ($rs_dbic->first->cds->all);
- at hashrefinf  = $rs_hashrefinf->all;
-
-is (scalar @dbic, scalar @hashrefinf, 'Equal number of tracks fetched');
-
-for my $index (0 .. $#hashrefinf) {
-    my $track       = $dbic[$index];
-    my $datahashref = $hashrefinf[$index];
-
-    is ($track->cd->artist->name, $datahashref->{name}, 'Brought back correct artist');
-    for my $col (keys %{$datahashref->{cds}{tracks}}) {
-        is ($track->get_column ($col), $datahashref->{cds}{tracks}{$col}, "Correct track '$col'");
-    }
-}
-
-# check for same query as above but using extended columns syntax
-$rs_hashrefinf = $schema->resultset ('Artist')->search ({ 'me.artistid' => 1}, {
-    join     => { cds => 'tracks' },
-    columns  => {name => 'name', 'cds.tracks.title' => 'tracks.title', 'cds.tracks.cd' => 'tracks.cd'},
-    order_by => [qw/cds.cdid tracks.trackid/],
-});
-$rs_hashrefinf->result_class('DBIx::Class::ResultClass::HashRefInflator');
-is_deeply [$rs_hashrefinf->all], \@hashrefinf, 'Check query using extended columns syntax';

Deleted: DBIx-Class/0.08/trunk/t/68inflate_serialize.t
===================================================================
--- DBIx-Class/0.08/trunk/t/68inflate_serialize.t	2009-06-11 07:23:54 UTC (rev 6613)
+++ DBIx-Class/0.08/trunk/t/68inflate_serialize.t	2009-06-11 12:29:48 UTC (rev 6614)
@@ -1,86 +0,0 @@
-use strict;
-use warnings;  
-
-use Test::More;
-use lib qw(t/lib);
-use DBICTest;
-
-my $schema = DBICTest->init_schema();
-
-use Data::Dumper;
-
-my @serializers = (
-    {	module => 'YAML.pm',
-	inflater => sub { YAML::Load (shift) },
-	deflater => sub { die "Expecting a reference" unless (ref $_[0]); YAML::Dump (shift) },
-    },
-    {	module => 'Storable.pm',
-	inflater => sub { Storable::thaw (shift) },
-	deflater => sub { die "Expecting a reference" unless (ref $_[0]); Storable::nfreeze (shift) },
-    },
-);
-
-
-my $selected;
-foreach my $serializer (@serializers) {
-    eval { require $serializer->{module} };
-    unless ($@) {
-	$selected = $serializer;
-	last;
-    }
-}
-
-plan (skip_all => "No suitable serializer found") unless $selected;
-
-plan (tests => 8);
-DBICTest::Schema::Serialized->inflate_column( 'serialized',
-    { inflate => $selected->{inflater},
-      deflate => $selected->{deflater},
-    },
-);
-Class::C3->reinitialize;
-
-my $struct_hash = {
-    a => 1,
-    b => [ 
-        { c => 2 },
-    ],
-    d => 3,
-};
-
-my $struct_array = [
-    'a', 
-    { 
-	b => 1,
-	c => 2
-    },
-    'd',
-];
-
-my $rs = $schema->resultset('Serialized');
-my $inflated;
-
-#======= testing hashref serialization
-
-my $object = $rs->create( { 
-    id => 1,
-    serialized => '',
-} );
-ok($object->update( { serialized => $struct_hash } ), 'hashref deflation');
-ok($inflated = $object->serialized, 'hashref inflation');
-is_deeply($inflated, $struct_hash, 'inflated hash matches original');
-
-$object = $rs->create( { 
-    id => 2,
-    serialized => '',
-} );
-eval { $object->set_inflated_column('serialized', $struct_hash) };
-ok(!$@, 'set_inflated_column to a hashref');
-is_deeply($object->serialized, $struct_hash, 'inflated hash matches original');
-
-
-#====== testing arrayref serialization
-
-ok($object->update( { serialized => $struct_array } ), 'arrayref deflation');
-ok($inflated = $object->serialized, 'arrayref inflation');
-is_deeply($inflated, $struct_array, 'inflated array matches original');

Copied: DBIx-Class/0.08/trunk/t/inflate/core.t (from rev 6400, DBIx-Class/0.08/trunk/t/68inflate.t)
===================================================================
--- DBIx-Class/0.08/trunk/t/inflate/core.t	                        (rev 0)
+++ DBIx-Class/0.08/trunk/t/inflate/core.t	2009-06-11 12:29:48 UTC (rev 6614)
@@ -0,0 +1,113 @@
+use strict;
+use warnings;  
+
+use Test::More;
+use lib qw(t/lib);
+use DBICTest;
+
+my $schema = DBICTest->init_schema();
+
+eval { require DateTime };
+plan skip_all => "Need DateTime for inflation tests" if $@;
+
+plan tests => 22;
+
+$schema->class('CD') ->inflate_column( 'year',
+    { inflate => sub { DateTime->new( year => shift ) },
+      deflate => sub { shift->year } }
+);
+
+# inflation test
+my $cd = $schema->resultset("CD")->find(3);
+
+is( ref($cd->year), 'DateTime', 'year is a DateTime, ok' );
+
+is( $cd->year->year, 1997, 'inflated year ok' );
+
+is( $cd->year->month, 1, 'inflated month ok' );
+
+eval { $cd->year(\'year +1'); };
+ok(!$@, 'updated year using a scalarref');
+$cd->update();
+$cd->discard_changes();
+
+is( ref($cd->year), 'DateTime', 'year is still a DateTime, ok' );
+
+is( $cd->year->year, 1998, 'updated year, bypassing inflation' );
+
+is( $cd->year->month, 1, 'month is still 1' );  
+
+# get_inflated_column test
+
+is( ref($cd->get_inflated_column('year')), 'DateTime', 'get_inflated_column produces a DateTime');
+
+# deflate test
+my $now = DateTime->now;
+$cd->year( $now );
+$cd->update;
+
+$cd = $schema->resultset("CD")->find(3);
+is( $cd->year->year, $now->year, 'deflate ok' );
+
+# set_inflated_column test
+eval { $cd->set_inflated_column('year', $now) };
+ok(!$@, 'set_inflated_column with DateTime object');
+$cd->update;
+
+$cd = $schema->resultset("CD")->find(3);                 
+is( $cd->year->year, $now->year, 'deflate ok' );
+
+$cd = $schema->resultset("CD")->find(3);                 
+my $before_year = $cd->year->year;
+eval { $cd->set_inflated_column('year', \'year + 1') };
+ok(!$@, 'set_inflated_column to "year + 1"');
+$cd->update;
+
+TODO: {
+  local $TODO = 'this was left in without a TODO - should it work?';
+
+  eval {
+    $cd->store_inflated_column('year', \'year + 1');
+    is_deeply( $cd->year, \'year + 1', 'deflate ok' );
+  };
+  ok(!$@, 'store_inflated_column to "year + 1"');
+}
+
+$cd = $schema->resultset("CD")->find(3);                 
+is( $cd->year->year, $before_year+1, 'deflate ok' );
+
+# store_inflated_column test
+$cd = $schema->resultset("CD")->find(3);                 
+eval { $cd->store_inflated_column('year', $now) };
+ok(!$@, 'store_inflated_column with DateTime object');
+$cd->update;
+
+is( $cd->year->year, $now->year, 'deflate ok' );
+
+# update tests
+$cd = $schema->resultset("CD")->find(3);                 
+eval { $cd->update({'year' => $now}) };
+ok(!$@, 'update using DateTime object ok');
+is($cd->year->year, $now->year, 'deflate ok');
+
+$cd = $schema->resultset("CD")->find(3);                 
+$before_year = $cd->year->year;
+eval { $cd->update({'year' => \'year + 1'}) };
+ok(!$@, 'update using scalarref ok');
+
+$cd = $schema->resultset("CD")->find(3);                 
+is($cd->year->year, $before_year + 1, 'deflate ok');
+
+# discard_changes test
+$cd = $schema->resultset("CD")->find(3);                 
+# inflate the year
+$before_year = $cd->year->year;
+$cd->update({ year => \'year + 1'});
+$cd->discard_changes;
+
+is($cd->year->year, $before_year + 1, 'discard_changes clears the inflated value');
+
+my $copy = $cd->copy({ year => $now, title => "zemoose" });
+
+isnt( $copy->year->year, $before_year, "copy" );
+ 

Copied: DBIx-Class/0.08/trunk/t/inflate/hri.t (from rev 6400, DBIx-Class/0.08/trunk/t/68inflate_resultclass_hashrefinflator.t)
===================================================================
--- DBIx-Class/0.08/trunk/t/inflate/hri.t	                        (rev 0)
+++ DBIx-Class/0.08/trunk/t/inflate/hri.t	2009-06-11 12:29:48 UTC (rev 6614)
@@ -0,0 +1,126 @@
+use strict;
+use warnings;  
+
+use Test::More qw(no_plan);
+use lib qw(t/lib);
+use DBICTest;
+my $schema = DBICTest->init_schema();
+
+
+# Under some versions of SQLite if the $rs is left hanging around it will lock
+# So we create a scope here cos I'm lazy
+{
+    my $rs = $schema->resultset('CD');
+
+    # get the defined columns
+    my @dbic_cols = sort $rs->result_source->columns;
+
+    # use the hashref inflator class as result class
+    $rs->result_class('DBIx::Class::ResultClass::HashRefInflator');
+
+    # fetch first record
+    my $datahashref1 = $rs->first;
+
+    my @hashref_cols = sort keys %$datahashref1;
+
+    is_deeply( \@dbic_cols, \@hashref_cols, 'returned columns' );
+}
+
+
+sub check_cols_of {
+    my ($dbic_obj, $datahashref) = @_;
+    
+    foreach my $col (keys %$datahashref) {
+        # plain column
+        if (not ref ($datahashref->{$col}) ) {
+            is ($datahashref->{$col}, $dbic_obj->get_column($col), 'same value');
+        }
+        # related table entry (belongs_to)
+        elsif (ref ($datahashref->{$col}) eq 'HASH') {
+            check_cols_of($dbic_obj->$col, $datahashref->{$col});
+        }
+        # multiple related entries (has_many)
+        elsif (ref ($datahashref->{$col}) eq 'ARRAY') {
+            my @dbic_reltable = $dbic_obj->$col;
+            my @hashref_reltable = @{$datahashref->{$col}};
+  
+            is (scalar @hashref_reltable, scalar @dbic_reltable, 'number of related entries');
+
+            # for my $index (0..scalar @hashref_reltable) {
+            for my $index (0..scalar @dbic_reltable) {
+                my $dbic_reltable_obj       = $dbic_reltable[$index];
+                my $hashref_reltable_entry  = $hashref_reltable[$index];
+                
+                check_cols_of($dbic_reltable_obj, $hashref_reltable_entry);
+            }
+        }
+    }
+}
+
+# create a cd without tracks for testing empty has_many relationship
+$schema->resultset('CD')->create({ title => 'Silence is golden', artist => 3, year => 2006 });
+
+# order_by to ensure both resultsets have the rows in the same order
+# also check result_class-as-an-attribute syntax
+my $rs_dbic = $schema->resultset('CD')->search(undef,
+    {
+        prefetch    => [ qw/ artist tracks / ],
+        order_by    => [ 'me.cdid', 'tracks.position' ],
+    }
+);
+my $rs_hashrefinf = $schema->resultset('CD')->search(undef,
+    {
+        prefetch    => [ qw/ artist tracks / ],
+        order_by    => [ 'me.cdid', 'tracks.position' ],
+        result_class => 'DBIx::Class::ResultClass::HashRefInflator',
+    }
+);
+
+my @dbic        = $rs_dbic->all;
+my @hashrefinf  = $rs_hashrefinf->all;
+
+for my $index (0 .. $#hashrefinf) {
+    my $dbic_obj    = $dbic[$index];
+    my $datahashref = $hashrefinf[$index];
+
+    check_cols_of($dbic_obj, $datahashref);
+}
+
+# sometimes for ultra-mega-speed you want to fetch columns in esoteric ways
+# check the inflator over a non-fetching join 
+$rs_dbic = $schema->resultset ('Artist')->search ({ 'me.artistid' => 1}, {
+    prefetch => { cds => 'tracks' },
+    order_by => [qw/cds.cdid tracks.trackid/],
+});
+
+$rs_hashrefinf = $schema->resultset ('Artist')->search ({ 'me.artistid' => 1}, {
+    join     => { cds => 'tracks' },
+    select   => [qw/name   tracks.title      tracks.cd       /],
+    as       => [qw/name   cds.tracks.title  cds.tracks.cd   /],
+    order_by => [qw/cds.cdid tracks.trackid/],
+    result_class => 'DBIx::Class::ResultClass::HashRefInflator',
+});
+
+ at dbic = map { $_->tracks->all } ($rs_dbic->first->cds->all);
+ at hashrefinf  = $rs_hashrefinf->all;
+
+is (scalar @dbic, scalar @hashrefinf, 'Equal number of tracks fetched');
+
+for my $index (0 .. $#hashrefinf) {
+    my $track       = $dbic[$index];
+    my $datahashref = $hashrefinf[$index];
+
+    is ($track->cd->artist->name, $datahashref->{name}, 'Brought back correct artist');
+    for my $col (keys %{$datahashref->{cds}{tracks}}) {
+        is ($track->get_column ($col), $datahashref->{cds}{tracks}{$col}, "Correct track '$col'");
+    }
+}
+
+# check for same query as above but using extended columns syntax
+$rs_hashrefinf = $schema->resultset ('Artist')->search ({ 'me.artistid' => 1}, {
+    join     => { cds => 'tracks' },
+    columns  => {name => 'name', 'cds.tracks.title' => 'tracks.title', 'cds.tracks.cd' => 'tracks.cd'},
+    order_by => [qw/cds.cdid tracks.trackid/],
+});
+$rs_hashrefinf->result_class('DBIx::Class::ResultClass::HashRefInflator');
+is_deeply [$rs_hashrefinf->all], \@hashrefinf, 'Check query using extended columns syntax';

Copied: DBIx-Class/0.08/trunk/t/inflate/serialize.t (from rev 6400, DBIx-Class/0.08/trunk/t/68inflate_serialize.t)
===================================================================
--- DBIx-Class/0.08/trunk/t/inflate/serialize.t	                        (rev 0)
+++ DBIx-Class/0.08/trunk/t/inflate/serialize.t	2009-06-11 12:29:48 UTC (rev 6614)
@@ -0,0 +1,86 @@
+use strict;
+use warnings;  
+
+use Test::More;
+use lib qw(t/lib);
+use DBICTest;
+
+my $schema = DBICTest->init_schema();
+
+use Data::Dumper;
+
+my @serializers = (
+    {	module => 'YAML.pm',
+	inflater => sub { YAML::Load (shift) },
+	deflater => sub { die "Expecting a reference" unless (ref $_[0]); YAML::Dump (shift) },
+    },
+    {	module => 'Storable.pm',
+	inflater => sub { Storable::thaw (shift) },
+	deflater => sub { die "Expecting a reference" unless (ref $_[0]); Storable::nfreeze (shift) },
+    },
+);
+
+
+my $selected;
+foreach my $serializer (@serializers) {
+    eval { require $serializer->{module} };
+    unless ($@) {
+	$selected = $serializer;
+	last;
+    }
+}
+
+plan (skip_all => "No suitable serializer found") unless $selected;
+
+plan (tests => 8);
+DBICTest::Schema::Serialized->inflate_column( 'serialized',
+    { inflate => $selected->{inflater},
+      deflate => $selected->{deflater},
+    },
+);
+Class::C3->reinitialize;
+
+my $struct_hash = {
+    a => 1,
+    b => [ 
+        { c => 2 },
+    ],
+    d => 3,
+};
+
+my $struct_array = [
+    'a', 
+    { 
+	b => 1,
+	c => 2
+    },
+    'd',
+];
+
+my $rs = $schema->resultset('Serialized');
+my $inflated;
+
+#======= testing hashref serialization
+
+my $object = $rs->create( { 
+    id => 1,
+    serialized => '',
+} );
+ok($object->update( { serialized => $struct_hash } ), 'hashref deflation');
+ok($inflated = $object->serialized, 'hashref inflation');
+is_deeply($inflated, $struct_hash, 'inflated hash matches original');
+
+$object = $rs->create( { 
+    id => 2,
+    serialized => '',
+} );
+eval { $object->set_inflated_column('serialized', $struct_hash) };
+ok(!$@, 'set_inflated_column to a hashref');
+is_deeply($object->serialized, $struct_hash, 'inflated hash matches original');
+
+
+#====== testing arrayref serialization
+
+ok($object->update( { serialized => $struct_array } ), 'arrayref deflation');
+ok($inflated = $object->serialized, 'arrayref inflation');
+is_deeply($inflated, $struct_array, 'inflated array matches original');




More information about the Bast-commits mailing list