test empty path part
[catagits/CatalystX-Routes.git] / t / routes.t
CommitLineData
c4057ce2 1use strict;
2use warnings;
3
4use Test::More 0.88;
5
6use lib 't/lib';
69d9fc4e 7use Catalyst::Test 'MyApp1';
8use HTTP::Request::Common qw( GET PUT POST DELETE );
c4057ce2 9
77d62699 10{
3c476900 11 request( GET '/foo', ( Accept => 'application/json' ) );
77d62699 12
13 is(
14 $MyApp1::Controller::C1::REQ{get}, 1,
15 'GET request for /foo went to the right sub'
16 );
17
3c476900 18 request( GET '/foo', ( Accept => '*/*', ) );
77d62699 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{
ffc58823 48 request( GET '/c1/bar', ( Accept => 'application/json' ) );
77d62699 49
50 is(
51 $MyApp1::Controller::C1::REQ{get}, 2,
ffc58823 52 'GET request for /c1/bar went to the right sub'
77d62699 53 );
54
ffc58823 55 request( GET '/c1/bar', ( Accept => '*/*', ) );
77d62699 56
57 is(
58 $MyApp1::Controller::C1::REQ{get_html}, 2,
ffc58823 59 'GET request for /c1/bar that looks like a browser went to the right sub'
77d62699 60 );
61
ffc58823 62 request( POST '/c1/bar' );
77d62699 63
64 is(
65 $MyApp1::Controller::C1::REQ{post}, 2,
ffc58823 66 'POST request for /c1/bar went to the right sub'
77d62699 67 );
68
ffc58823 69 request( PUT '/c1/bar' );
77d62699 70
71 is(
72 $MyApp1::Controller::C1::REQ{put}, 2,
ffc58823 73 'PUT request for /c1/bar went to the right sub'
77d62699 74 );
75
ffc58823 76 request( DELETE '/c1/bar' );
77d62699 77
78 is(
79 $MyApp1::Controller::C1::REQ{delete}, 2,
ffc58823 80 'DELETE request for /c1/bar went to the right sub'
77d62699 81 );
82}
83
84{
73bef299 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{
ba806aaf 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{
77d62699 118 get('/normal');
119
120 is(
121 $MyApp1::Controller::C1::REQ{normal}, 1,
957b8a41 122 'GET request for /normal went to the right sub'
77d62699 123 );
124
125 request( POST '/normal' );
126
127 is(
128 $MyApp1::Controller::C1::REQ{normal}, 2,
957b8a41 129 'POST request for /normal went to the right sub'
77d62699 130 );
131}
c4057ce2 132
133done_testing();