X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Finflate%2Fserialize.t;h=87fb7ce7828663b1a2dbe15b05d000be8d3f0d59;hb=68de943862f06cabd397d2e74d12cd9cdc999779;hp=c2be971efea32c33ad9e70494dbebe7ca2db9f54;hpb=497d874ac78f5b6bba1309001f62c299a9419499;p=dbsrgits%2FDBIx-Class.git diff --git a/t/inflate/serialize.t b/t/inflate/serialize.t index c2be971..87fb7ce 100644 --- a/t/inflate/serialize.t +++ b/t/inflate/serialize.t @@ -1,5 +1,5 @@ use strict; -use warnings; +use warnings; use Test::More; use lib qw(t/lib); @@ -7,16 +7,14 @@ 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 => '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) }, + { module => 'Storable.pm', + inflater => sub { Storable::thaw (shift) }, + deflater => sub { die "Expecting a reference" unless (ref $_[0]); Storable::nfreeze (shift) }, }, ); @@ -25,14 +23,13 @@ my $selected; foreach my $serializer (@serializers) { eval { require $serializer->{module} }; unless ($@) { - $selected = $serializer; - last; + $selected = $serializer; + last; } } plan (skip_all => "No suitable serializer found") unless $selected; -plan (tests => 11); DBICTest::Schema::Serialized->inflate_column( 'serialized', { inflate => $selected->{inflater}, deflate => $selected->{deflater}, @@ -42,17 +39,17 @@ Class::C3->reinitialize; my $struct_hash = { a => 1, - b => [ + b => [ { c => 2 }, ], d => 3, }; my $struct_array = [ - 'a', - { - b => 1, - c => 2 + 'a', + { + b => 1, + c => 2, }, 'd', ]; @@ -63,7 +60,6 @@ my $inflated; #======= testing hashref serialization my $object = $rs->create( { - id => 1, serialized => '', } ); ok($object->update( { serialized => $struct_hash } ), 'hashref deflation'); @@ -71,13 +67,19 @@ 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'); +$object->set_inflated_column('serialized', $struct_hash); is_deeply($object->serialized, $struct_hash, 'inflated hash matches original'); +$object = $rs->new({}); +$object->serialized ($struct_hash); +$object->insert; +is_deeply ( + $rs->find ({id => $object->id})->serialized, + $struct_hash, + 'new/insert works', +); #====== testing arrayref serialization @@ -85,8 +87,16 @@ ok($object->update( { serialized => $struct_array } ), 'arrayref deflation'); ok($inflated = $object->serialized, 'arrayref inflation'); is_deeply($inflated, $struct_array, 'inflated array matches original'); +$object = $rs->new({}); +$object->serialized ($struct_array); +$object->insert; +is_deeply ( + $rs->find ({id => $object->id})->serialized, + $struct_array, + 'new/insert works', +); -#===== make sure make_column_dirty ineracts reasonably with inflation +#===== make sure make_column_dirty interacts reasonably with inflation $object = $rs->first; $object->update ({serialized => { x => 'y'}}); @@ -98,3 +108,5 @@ $object->make_column_dirty('serialized'); $object->update; is_deeply ($rs->first->serialized, { x => 'z' }, 'changes made it to the db' ); + +done_testing;