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