test empty path part
[catagits/CatalystX-Routes.git] / t / routes.t
1 use strict;
2 use warnings;
3
4 use Test::More 0.88;
5
6 use lib 't/lib';
7 use Catalyst::Test 'MyApp1';
8 use HTTP::Request::Common qw( GET PUT POST DELETE );
9
10 {
11     request( GET '/foo', ( Accept => 'application/json' ) );
12
13     is(
14         $MyApp1::Controller::C1::REQ{get}, 1,
15         'GET request for /foo went to the right sub'
16     );
17
18     request( GET '/foo', ( Accept => '*/*', ) );
19
20     is(
21         $MyApp1::Controller::C1::REQ{get_html}, 1,
22         'GET request for /foo that looks like a browser went to the right sub'
23     );
24
25     request( POST '/foo' );
26
27     is(
28         $MyApp1::Controller::C1::REQ{post}, 1,
29         'POST request for /foo went to the right sub'
30     );
31
32     request( PUT '/foo' );
33
34     is(
35         $MyApp1::Controller::C1::REQ{put}, 1,
36         'PUT request for /foo went to the right sub'
37     );
38
39     request( DELETE '/foo' );
40
41     is(
42         $MyApp1::Controller::C1::REQ{delete}, 1,
43         'DELETE request for /foo went to the right sub'
44     );
45 }
46
47 {
48     request( GET '/c1/bar', ( Accept => 'application/json' ) );
49
50     is(
51         $MyApp1::Controller::C1::REQ{get}, 2,
52         'GET request for /c1/bar went to the right sub'
53     );
54
55     request( GET '/c1/bar', ( Accept => '*/*', ) );
56
57     is(
58         $MyApp1::Controller::C1::REQ{get_html}, 2,
59         'GET request for /c1/bar that looks like a browser went to the right sub'
60     );
61
62     request( POST '/c1/bar' );
63
64     is(
65         $MyApp1::Controller::C1::REQ{post}, 2,
66         'POST request for /c1/bar went to the right sub'
67     );
68
69     request( PUT '/c1/bar' );
70
71     is(
72         $MyApp1::Controller::C1::REQ{put}, 2,
73         'PUT request for /c1/bar went to the right sub'
74     );
75
76     request( DELETE '/c1/bar' );
77
78     is(
79         $MyApp1::Controller::C1::REQ{delete}, 2,
80         'DELETE request for /c1/bar went to the right sub'
81     );
82 }
83
84 {
85     get('/chain1/42/chain2/84/baz/foo');
86
87     is(
88         $MyApp1::Controller::C1::REQ{chain1}, 42,
89         'chain1 chain point captured the first arg'
90     );
91
92     is(
93         $MyApp1::Controller::C1::REQ{chain2}, 84,
94         'chain2 chain point captured the second arg'
95     );
96
97     is(
98         $MyApp1::Controller::C1::REQ{baz}, 'foo',
99         'baz route captured the third arg'
100     );
101 }
102
103 {
104     get('/user/99');
105
106     is(
107         $MyApp1::Controller::C1::REQ{user}, 99,
108         'get /user/99 calls _set_user chain point'
109     );
110
111     is(
112         $MyApp1::Controller::C1::REQ{empty}, 99,
113         'get /user/99 calls get chained from _set_user'
114     );
115 }
116
117 {
118     get('/normal');
119
120     is(
121         $MyApp1::Controller::C1::REQ{normal}, 1,
122         'GET request for /normal went to the right sub'
123     );
124
125     request( POST '/normal' );
126
127     is(
128         $MyApp1::Controller::C1::REQ{normal}, 2,
129         'POST request for /normal went to the right sub'
130     );
131 }
132
133 done_testing();