test case and proposed fix
[catagits/Catalyst-Runtime.git] / t / relative_root_action_for_bug.t
CommitLineData
518b6198 1use Test::Most;
2
3{
4 package MyApp::Controller::Root;
5 $INC{'MyApp/Controller/Root.pm'} = __FILE__;
6
7 use Moose;
8 use MooseX::MethodAttributes;
9
10 extends 'Catalyst::Controller';
11
12 sub root :Chained(/) PathPart('') CaptureArgs(0) {
13 my ($self, $c) = @_;
14 }
15
16 sub top :Chained('root') Args(0) {
17 my ($self, $c) = @_;
18 Test::Most::is $self->action_for('top'), 'top';
19 Test::Most::is $self->action_for('story/story'), 'story/story';
20
21 #warn ref($c)->dispatcher->get_action('story/story', '/root');
22
23 #use Devel::Dwarn;
24 #Dwarn ref($c)->dispatcher->_action_hash->{'story/story'};
25 }
26
27 MyApp::Controller::Root->config(namespace=>'');
28
29 package MyApp::Controller::Story;
30 $INC{'MyApp/Controller/Story.pm'} = __FILE__;
31
32 use Moose;
33 use MooseX::MethodAttributes;
34
35 extends 'Catalyst::Controller';
36
37 sub root :Chained(/root) PathPart('') CaptureArgs(0) {
38 my ($self, $c) = @_;
39 }
40
41 sub story :Chained(root) Args(0) {
42 my ($self, $c) = @_;
43
44 Test::Most::is $self->action_for('story'), 'story/story';
45 Test::Most::is $self->action_for('author/author'), 'story/author/author';
46 }
47
48 __PACKAGE__->meta->make_immutable;
49
50 package MyApp::Controller::Story::Author;
51 $INC{'MyApp/Controller/Story/Author.pm'} = __FILE__;
52
53 use Moose;
54 use MooseX::MethodAttributes;
55
56 extends 'Catalyst::Controller';
57
58 sub root :Chained(/story/root) PathPart('') CaptureArgs(0) {
59 my ($self, $c) = @_;
60 }
61
62 sub author :Chained(root) Args(0) {
63 my ($self, $c, $id) = @_;
64 Test::Most::is $self->action_for('author'), 'story/author/author';
65 }
66
67
68 __PACKAGE__->meta->make_immutable;
69
70 package MyApp;
71 $INC{'MyApp.pm'} = __FILE__;
72
73 use Catalyst;
74
75 MyApp->setup;
76}
77
78use Catalyst::Test 'MyApp';
79
80ok request '/story';
81ok request '/author';
82ok request '/top';
83
84done_testing(8);
85