Commit | Line | Data |
7656dd12 |
1 | use strict; |
2 | use warnings; |
5213846d |
3 | use Test::More 0.88; |
7656dd12 |
4 | use FindBin; |
3c4306f2 |
5 | use Data::Dumper; |
7656dd12 |
6 | use lib ( "$FindBin::Bin/lib", "$FindBin::Bin/../lib" ); |
7 | use Test::Rest; |
8 | |
9 | # Should use the default serializer, YAML |
10 | my $t = Test::Rest->new( 'content_type' => 'text/plain' ); |
11 | |
12 | use_ok 'Catalyst::Test', 'Test::Catalyst::Action::REST'; |
13 | |
3c4306f2 |
14 | foreach my $endpoint (qw/ test other_test /) { |
15 | foreach my $method (qw(GET DELETE POST PUT OPTIONS)) { |
16 | my $run_method = lc($method); |
17 | my $res; |
18 | if ( grep /$method/, qw(GET DELETE OPTIONS) ) { |
19 | $res = request( $t->$run_method( url => '/actions/' . $endpoint ) ); |
20 | } |
21 | else { |
22 | $res = request( |
23 | $t->$run_method( |
24 | url => '/actions/' . $endpoint, |
25 | data => '', |
26 | ) |
27 | ); |
28 | } |
29 | ok( $res->is_success, "$method request succeeded" ) or warn Dumper($res); |
30 | is( |
31 | $res->content, |
32 | "$method", |
33 | "$method request had proper response" |
34 | ); |
35 | is( |
36 | $res->header('X-Was-In-TopLevel'), |
37 | '1', |
38 | "went through top level action for dispatching to $method" |
39 | ); |
40 | is( |
41 | $res->header('Using-Action'), |
42 | 'STATION', |
43 | "went through action for dispatching to $method" |
7656dd12 |
44 | ); |
45 | } |
7656dd12 |
46 | } |
47 | |
ecb598ef |
48 | my $head_res = request( $t->head(url => '/actions/test') ); |
49 | ok($head_res->is_success, 'HEAD request succeeded') |
50 | or diag($head_res->code); |
51 | ok(!$head_res->content, 'HEAD request had proper response'); |
52 | |
5213846d |
53 | my $res = request( |
54 | $t->put( |
55 | url => '/actions/test', |
56 | data => '', |
57 | ) |
58 | ); |
59 | is( |
60 | $res->header('Using-Action'), |
61 | 'STATION', |
62 | "went through action for dispatching to PUT" |
63 | ); |
64 | is( |
65 | $res->header('Using-Sub-Action'), |
66 | 'MOO', |
67 | "went through sub action for dispatching to PUT" |
68 | ); |
69 | |
70 | done_testing; |