* fix a bug where if a required constructor argument was not serialized, it was
[gitmo/MooseX-Storage.git] / t / 008_do_not_serialize.t
index bdf2091..adc8e14 100644 (file)
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 6;
+use Test::More tests => 11;
 use Test::Exception;
 
 BEGIN {
@@ -37,22 +37,60 @@ BEGIN {
     1;
 }
 
-my $foo = Foo->new;
-isa_ok($foo, 'Foo');
-
-is($foo->bar, 'BAR', '... got the value we expected');
-is($foo->baz, 'BAZ', '... got the value we expected');
-is($foo->gorch, 'GORCH', '... got the value we expected');
+{   my $foo = Foo->new;
+    isa_ok($foo, 'Foo');
+    
+    is($foo->bar, 'BAR', '... got the value we expected');
+    is($foo->baz, 'BAZ', '... got the value we expected');
+    is($foo->gorch, 'GORCH', '... got the value we expected');
+    
+    is_deeply(
+        $foo->pack,
+        {
+            __CLASS__ => 'Foo',
+            gorch     => 'GORCH'
+        },
+        '... got the right packed class data'
+    );
+}
 
-is_deeply(
-    $foo->pack,
-    {
-        __CLASS__ => 'Foo',
-        gorch     => 'GORCH'
-    },
-    '... got the right packed class data'
-);
+### more involved test; required attribute that's not serialized
+{   package Bar;
+    use Moose;
+    use MooseX::Storage;
 
+    with Storage;
 
+    has foo => (
+        metaclass   => 'DoNotSerialize',
+        required    => 1,
+        is          => 'rw',
+    );
+    
+    has zot => (
+        default     => sub { $$ },
+        is          => 'rw',
+    );        
+}
 
+{   my $bar = Bar->new( foo => $$ );
+    
+    ok( $bar,                   "New object created" );
+    is( $bar->foo, $$,          "   ->foo => $$" );
+    is( $bar->zot, $$,          "   ->zot => $$" );
+    
+    my $bpack = $bar->pack;
+    is_deeply(
+        $bpack,
+        {   __CLASS__   => 'Bar',
+            zot         => $$,
+        },                      "   Packed correctly" );
+        
+    my $bar2 = Bar->unpack({ %$bpack, foo => $$ });
+    ok( $bar2,                  "   Unpacked correctly by supplying foo => $$"); 
+}        
+            
+        
+        
+