cafb13a06ba66e43bdf2f257f00d0d57e33f8875
[gitmo/MooseX-Storage.git] / t / 005_w_versions_and_authority_check.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 8;
7 use Test::Deep;
8 use Test::Fatal;
9
10 BEGIN {
11     use_ok('MooseX::Storage');
12 }
13
14 =pod
15
16 This tests that the version and authority 
17 checks are performed upon object expansion.
18
19 =cut
20
21 {
22     package Bar;
23     use Moose;
24     use MooseX::Storage;
25     
26     our $VERSION   = '0.01';
27     our $AUTHORITY = 'cpan:JRANDOM';
28
29     with Storage;
30     
31     has 'number' => (is => 'ro', isa => 'Int');
32     
33     package Foo;
34     use Moose;
35     use MooseX::Storage;
36
37     our $VERSION   = '0.01';
38     our $AUTHORITY = 'cpan:JRANDOM';    
39
40     with Storage;    
41
42     has 'bar' => ( 
43         is  => 'ro', 
44         isa => 'Bar' 
45     );    
46 }
47
48 {
49     my $foo = Foo->new(
50         bar => Bar->new(number => 1)
51     );
52     isa_ok( $foo, 'Foo' );
53     
54     cmp_deeply(
55         $foo->pack,
56         {
57             __CLASS__ => 'Foo-0.01-cpan:JRANDOM',
58             bar => {
59                 __CLASS__ => 'Bar-0.01-cpan:JRANDOM',
60                 number    => 1,
61             }         
62         },
63         '... got the right frozen class'
64     );
65 }
66
67 {
68     my $foo = Foo->unpack(
69         {
70             __CLASS__ => 'Foo-0.01-cpan:JRANDOM',
71             bar => {
72                 __CLASS__ => 'Bar-0.01-cpan:JRANDOM',
73                 number    => 1,
74             }         
75         },     
76     );
77     isa_ok( $foo, 'Foo' );
78     isa_ok( $foo->bar, 'Bar' );
79     is( $foo->bar->number, 1 , '... got the right number too' );
80     
81 }
82
83 Moose::Meta::Class->create('Bar', 
84     version   => '0.02',
85     authority => 'cpan:JRANDOM',
86 );
87
88 ok(exception {
89     Foo->unpack(
90         {
91             __CLASS__ => 'Foo-0.01-cpan:JRANDOM',
92             bar => {
93                 __CLASS__ => 'Bar-0.01-cpan:JRANDOM',
94                 number    => 1,
95             }         
96         }     
97     );
98 }, '... could not unpack, versions are different ' . $@);
99
100 Moose::Meta::Class->create('Bar', 
101     version   => '0.01',
102     authority => 'cpan:DSTATIC',
103 );
104
105 ok(exception {
106     Foo->unpack(
107         {
108             __CLASS__ => 'Foo-0.01-cpan:JRANDOM',
109             bar => {
110                 __CLASS__ => 'Bar-0.01-cpan:JRANDOM',
111                 number    => 1,
112             }         
113         }     
114     );
115 }, '... could not unpack, authorities are different');