Merge branch 'pr/135' into release-candidates/rc-5.90116
[catagits/Catalyst-Runtime.git] / t / relative_root_action_for_bug.t
1 use warnings;
2 use strict;
3 use Test::More;
4
5 {
6     package MyApp::Controller::Root;
7     $INC{'MyApp/Controller/Root.pm'} = __FILE__;
8
9     use Moose;
10     use MooseX::MethodAttributes;
11
12     extends 'Catalyst::Controller';
13
14     sub root :Chained(/) PathPart('') CaptureArgs(0) {
15       my ($self, $c) = @_;
16     }
17
18     sub top :Chained('root') Args(0) {
19       my ($self, $c) = @_;
20       Test::More::is $self->action_for('top'), 'top';
21       Test::More::is $self->action_for('story/story'), 'story/story';
22     }
23
24     sub default : Path {
25
26         my ($self, $c) = @_;
27         $c->response->body("Ok");
28     }
29
30     MyApp::Controller::Root->config(namespace=>'');
31
32     package MyApp::Controller::Story;
33     $INC{'MyApp/Controller/Story.pm'} = __FILE__;
34
35     use Moose;
36     use MooseX::MethodAttributes;
37
38     extends 'Catalyst::Controller';
39
40     sub root :Chained(/root) PathPart('') CaptureArgs(0) {
41       my ($self, $c) = @_;
42     }
43
44     sub story :Chained(root) Args(0) {
45       my ($self, $c) = @_;
46
47       Test::More::is $self->action_for('story'), 'story/story';
48       Test::More::is $self->action_for('author/author'), 'story/author/author';
49     }
50
51     __PACKAGE__->meta->make_immutable;
52
53     package MyApp::Controller::Story::Author;
54     $INC{'MyApp/Controller/Story/Author.pm'} = __FILE__;
55
56     use Moose;
57     use MooseX::MethodAttributes;
58
59     extends 'Catalyst::Controller';
60
61     sub root :Chained(/story/root) PathPart('') CaptureArgs(0) {
62       my ($self, $c) = @_;
63     }
64
65     sub author :Chained(root) Args(0) {
66       my ($self, $c, $id) = @_;
67       Test::More::is $self->action_for('author'), 'story/author/author';
68       Test::More::is $self->action_for('../story'), 'story/story';
69       Test::More::is $self->action_for('../../top'), 'top';
70     }
71
72     __PACKAGE__->meta->make_immutable;
73
74     package MyApp;
75     $INC{'MyApp.pm'} = __FILE__;
76
77     use Catalyst;
78
79     MyApp->setup;
80 }
81
82 use Catalyst::Test 'MyApp';
83
84 ok request '/top';
85 ok request '/story';
86 ok request '/author';
87 ok request '/double';
88 ok request '/double/file.ext';
89 ok request '/double/file..ext';
90
91
92 done_testing(13);
93