From: Matt S Trout Date: Thu, 7 Jun 2007 20:16:34 +0000 (+0000) Subject: test fixups X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8b621a877d0bfcaa308c4834b7f94274b1c4ce43;p=dbsrgits%2FDBIx-Class-Historic.git test fixups --- diff --git a/Changes b/Changes index 35498ae..f080fd7 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,6 @@ Revision history for DBIx::Class + - Test cleanup and doc note (ribasushi) - More documentation updates - Error messages from ->deploy made more informative - connect_info will now always return the arguments it was diff --git a/lib/DBIx/Class/Row.pm b/lib/DBIx/Class/Row.pm index e6e5ebc..9f03d83 100644 --- a/lib/DBIx/Class/Row.pm +++ b/lib/DBIx/Class/Row.pm @@ -108,7 +108,8 @@ required. Also takes an options hashref of C<< column_name => value> pairs >> to update first. But be aware that this hashref might be edited in place, so dont rely on -it being the same after a call to C. +it being the same after a call to C. If you need to preserve the hashref, +it is sufficient to pass a shallow copy to C, e.g. ( { %{ $href } } ) =cut diff --git a/t/68inflate_serialize.t b/t/68inflate_serialize.t index 2efabbf..59c0997 100644 --- a/t/68inflate_serialize.t +++ b/t/68inflate_serialize.t @@ -40,43 +40,47 @@ DBICTest::Schema::Serialized->inflate_column( 'serialized', ); Class::C3->reinitialize; -my $complex1 = { - id => 1, - serialized => { - a => 1, - b => [ - { c => 2 }, - ], - d => 3, - }, +my $struct_hash = { + a => 1, + b => [ + { c => 2 }, + ], + d => 3, }; -my $complex2 = { - id => 1, - serialized => [ - 'a', - { b => 1, c => 2}, - 'd', - ], -}; +my $struct_array = [ + 'a', + { + b => 1, + c => 2 + }, + 'd', +]; my $rs = $schema->resultset('Serialized'); -my $entry = $rs->create({ id => 1, serialized => ''}); - my $inflated; -ok($entry->update ({ %{$complex1} }), 'hashref deflation ok'); -ok($inflated = $entry->serialized, 'hashref inflation ok'); -is_deeply($inflated, $complex1->{serialized}, 'inflated hash matches original'); - -my $entry2 = $rs->create({ id => 2, serialized => ''}); +#======= testing hashref serialization -eval { $entry2->set_inflated_column('serialized', $complex1->{serialized}) }; +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'); -$entry2->update; -is_deeply($entry2->serialized, $complex1->{serialized}, 'inflated hash matches original'); +is_deeply($object->serialized, $struct_hash, 'inflated hash matches original'); + -ok($entry->update ({ %{$complex2} }), 'arrayref deflation ok'); -ok($inflated = $entry->serialized, 'arrayref inflation ok'); -is_deeply($inflated, $complex2->{serialized}, 'inflated array 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');