From: Ricardo Signes Date: Fri, 2 Apr 2010 17:45:47 +0000 (-0400) Subject: tests for deferred and param roles X-Git-Tag: 0.27~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=54d6ff364f51d33839d796256e295f165e20fa7b;p=gitmo%2FMooseX-Storage.git tests for deferred and param roles --- diff --git a/t/012_param_json.t b/t/012_param_json.t index 5ce5c24..e694e1b 100644 --- a/t/012_param_json.t +++ b/t/012_param_json.t @@ -11,17 +11,15 @@ BEGIN { unless eval "require MooseX::Storage::Format::JSONpm; 1"; } -plan tests => 3; +plan tests => 6; use_ok('MooseX::Storage'); { - package Foo; use Moose; use MooseX::Storage; with Storage(format => [ JSONpm => { json_opts => { pretty => 1 } } ] ); - # with Storage(format => 'JSONpm'); has 'string' => ( is => 'ro', isa => 'Str' ); has 'float' => ( is => 'ro', isa => 'Num' ); @@ -44,3 +42,35 @@ use_ok('MooseX::Storage'); } +{ + package Bar; + use Moose; + use MooseX::Storage; + + our $VERSION = '0.01'; + + with 'MooseX::Storage::Deferred'; + + has 'x' => (is => 'rw', isa => 'Int'); + has 'y' => (is => 'rw', isa => 'Int'); +} + +for my $jsonpm ( + [ string => 'JSONpm' ], + [ aref0p => [ JSONpm => ] ], + [ aref1p => [ JSONpm => { json_opts => { pretty => 1 } } ] ], +) { + my ($name, $p) = @$jsonpm; + + my $json = eval { Bar->new(x => 10, y => 20)->freeze({ format => $p }) }; + + is_deeply( + JSON->new->decode($json), + { + '__CLASS__' => 'Bar-0.01', + x => 10, + y => 20, + }, + "correct deferred freeze from $name", + ); +}