t/001_basic.t - add ro test
[gitmo/Moose-Policy.git] / t / 001_basic.t
index 549a5c6..fced719 100644 (file)
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 1;
+use Test::More 'no_plan';
 
 BEGIN {
     use_ok('Moose::Policy');           
@@ -15,7 +15,9 @@ BEGIN {
     
     extends 'Moose::Meta::Attribute';
     
-    before '_process_options' => sub {
+    # this method (mostly stolen from M::M::Attribute) just rebuilds the
+    # options so anything with 'is' gets PBP accessors
+    sub _process_options {
         my ($class, $name, $options) = @_;
        if (exists $options->{is}) {
                if ($options->{is} eq 'ro') {
@@ -27,12 +29,14 @@ BEGIN {
                }
                delete $options->{is};
        }
-    };
+       
+        $class->SUPER::_process_options($name, $options);
+    }
 }
 
-
 {
     package My::Moose::Policy;
+    # policy just specifies metaclass delegates
     use constant attribute_metaclass => 'My::Moose::Meta::Attribute';
 }
 
@@ -42,9 +46,14 @@ BEGIN {
     use Moose::Policy 'My::Moose::Policy';
     use Moose;
     
-    has 'bar' => (default => 'Foo::bar');
+    has 'bar' => (is => 'rw', default => 'Foo::bar');
+    has 'baz' => (is => 'ro', default => 'Foo::baz');
 }
 
+isa_ok(Foo->meta, 'Moose::Meta::Class');
+is(Foo->meta->attribute_metaclass, 'My::Moose::Meta::Attribute', '... got our custom attr metaclass');
+
+isa_ok(Foo->meta->get_attribute('bar'), 'My::Moose::Meta::Attribute');
 
 my $foo = Foo->new;
 isa_ok($foo, 'Foo');
@@ -52,7 +61,10 @@ isa_ok($foo, 'Foo');
 can_ok($foo, 'get_bar');
 can_ok($foo, 'set_bar');
 
+can_ok($foo, 'get_baz');
+
 is($foo->get_bar, 'Foo::bar', '... got the right default value');
+is($foo->get_baz, 'Foo::baz', '... got the right default value');