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