a38a77a008fc1e08adad7523234f2b0db6ca7c2f
[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('/normal');
86
87     is(
88         $MyApp1::Controller::C1::REQ{normal}, 1,
89         'GET request for /normal went to the right sub'
90     );
91
92     request( POST '/normal' );
93
94     is(
95         $MyApp1::Controller::C1::REQ{normal}, 2,
96         'POST request for /normal went to the right sub'
97     );
98 }
99
100 done_testing();