Whitespace trim tests
[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
766ab81f 15This tests that the version and authority
c1830046 16checks are performed upon object expansion.
17
18=cut
19
20{
21 package Bar;
22 use Moose;
23 use MooseX::Storage;
766ab81f 24
c1830046 25 our $VERSION = '0.01';
26 our $AUTHORITY = 'cpan:JRANDOM';
27
28 with Storage;
766ab81f 29
c1830046 30 has 'number' => (is => 'ro', isa => 'Int');
766ab81f 31
c1830046 32 package Foo;
33 use Moose;
34 use MooseX::Storage;
35
36 our $VERSION = '0.01';
766ab81f 37 our $AUTHORITY = 'cpan:JRANDOM';
c1830046 38
766ab81f 39 with Storage;
c1830046 40
766ab81f 41 has 'bar' => (
42 is => 'ro',
43 isa => 'Bar'
44 );
c1830046 45}
46
47{
48 my $foo = Foo->new(
49 bar => Bar->new(number => 1)
50 );
51 isa_ok( $foo, 'Foo' );
766ab81f 52
c1830046 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,
766ab81f 60 }
c1830046 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,
766ab81f 73 }
74 },
c1830046 75 );
76 isa_ok( $foo, 'Foo' );
77 isa_ok( $foo->bar, 'Bar' );
78 is( $foo->bar->number, 1 , '... got the right number too' );
766ab81f 79
c1830046 80}
81
766ab81f 82Moose::Meta::Class->create('Bar',
c1830046 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,
766ab81f 94 }
95 }
c1830046 96 );
219c1cc5 97} '... could not unpack, versions are different ' . $@;
c1830046 98
766ab81f 99Moose::Meta::Class->create('Bar',
c1830046 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,
766ab81f 111 }
112 }
c1830046 113 );
114} '... could not unpack, authorities are different';