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