merged with delegation_bugs branch
[gitmo/MooseX-ClassAttribute.git] / t / 08-role-composition-of-delegates.t
1
2 # Reported in https://rt.cpan.org/Public/Bug/Display.html?id=59572
3
4 use strict;
5 use warnings;
6
7 use Test::More tests => 4;
8 #use Test::NoWarnings;
9 use Test::Exception;
10
11 {
12     package Role1;
13     use Moose::Role;
14
15     # I do nothing!
16 }
17 {
18     package Role2;
19
20     use Moose::Role;
21     use MooseX::ClassAttribute;
22
23     class_has attr => (
24         is => 'ro', isa => 'HashRef[Str]',
25         lazy => 1,
26         default => sub { {} },
27         traits => ['Hash'],
28         handles => {
29             has_attr => 'exists',
30         },
31     );
32     
33     has foo => ( is => 'rw' );
34
35     sub normal_method
36     {
37         Test::More::pass('a regular method from the role is composed');
38     }
39 }
40
41 {
42     package Foo;
43     use strict; use warnings;
44     use Moose;
45     with 'Role1', 'Role2';
46     1;
47 }
48
49 package main;
50 local $TODO = 'Class attributes are lost during role composition';
51 # this runs, so Role2 did get composed...
52 Foo->normal_method;
53 ok(Foo->can('foo'), 'Standard attribute applied ok');
54
55 # Except the delegated method ended up in the wrong place!
56
57 # ..and MX::Class never got applied properly!
58 ok(Moose::Util::does_role(Foo->meta, 'MooseX::ClassAttribute::Trait::Class'),
59     'metaclass gets MX:CA metaclass trait');
60
61 # in Moose 1.08/MooseX::ClassAttribute 0.16, this dies with:
62 # Can't locate object method "has_attr" via package "Foo"
63 lives_ok { Foo->has_attr('key') }
64     'Delegated method from native attribute trait is properly composed from a role composed in a list of roles';
65