do all the renaming that was discussed
[gitmo/Moose.git] / t / 070_attribute_helpers / 011_counter_with_defaults.t
1 #!/usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 use Test::More tests => 12;
7 use Test::Moose;
8
9 {
10     package MyHomePage;
11     use Moose;
12     use Moose::AttributeHelpers;
13
14     has 'counter' => ( traits => ['Counter'] );
15 }
16
17 my $page = MyHomePage->new();
18 isa_ok( $page, 'MyHomePage' );
19
20 can_ok( $page, $_ ) for qw[
21     dec_counter
22     inc_counter
23     reset_counter
24 ];
25
26 is( $page->counter, 0, '... got the default value' );
27
28 $page->inc_counter;
29 is( $page->counter, 1, '... got the incremented value' );
30
31 $page->inc_counter;
32 is( $page->counter, 2, '... got the incremented value (again)' );
33
34 $page->dec_counter;
35 is( $page->counter, 1, '... got the decremented value' );
36
37 $page->reset_counter;
38 is( $page->counter, 0, '... got the original value' );
39
40 # check the meta ..
41
42 my $counter = $page->meta->get_attribute('counter');
43 does_ok( $counter, 'Moose::Meta::Attribute::Trait::Native::Counter' );
44
45 is( $counter->type_constraint->name, 'Num',
46     '... got the expected default type constraint' );
47
48 is_deeply(
49     $counter->handles,
50     {
51         'inc_counter'   => 'inc',
52         'dec_counter'   => 'dec',
53         'reset_counter' => 'reset',
54         'set_counter'   => 'set',
55     },
56     '... got the right default handles methods'
57 );
58