Commit | Line | Data |
7656dd12 |
1 | use strict; |
2 | use warnings; |
3 | use Test::More tests => 23; |
4 | use FindBin; |
5 | |
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 | |
14 | foreach my $method (qw(GET DELETE POST PUT OPTIONS)) { |
15 | my $run_method = lc($method); |
16 | my $result = "something $method"; |
17 | my $res; |
18 | if ( grep /$method/, qw(GET DELETE OPTIONS) ) { |
19 | $res = request( $t->$run_method( url => '/actions/test' ) ); |
20 | } else { |
21 | $res = request( |
22 | $t->$run_method( |
23 | url => '/actions/test', |
24 | data => '', |
25 | ) |
26 | ); |
27 | } |
28 | ok( $res->is_success, "$method request succeeded" ); |
29 | is( |
30 | $res->content, |
31 | "something $method", |
32 | "$method request had proper response" |
33 | ); |
34 | is( |
35 | $res->header('Using-Action'), |
36 | 'STATION', |
37 | "went through action for dispatching to $method" |
38 | ); |
39 | } |
40 | |
41 | my $fail_res = request( $t->delete( url => '/actions/notreally' ) ); |
42 | is( $fail_res->code, 405, "Request to bad method gets 405 Not Implemented" ); |
43 | is( $fail_res->header('allow'), "GET", "405 allow header properly set." ); |
44 | |
45 | my $options_res = request( $t->options( url => '/actions/notreally' ) ); |
46 | is( $options_res->code, 200, "OPTIONS request handler succeeded" ); |
47 | is( $options_res->header('allow'), |
48 | "GET", "OPTIONS request allow header properly set." ); |
49 | |
50 | my $modified_res = request( $t->get( url => '/actions/not_modified' ) ); |
51 | is( $modified_res->code, 304, "Not Modified request handler succeeded" ); |
52 | |
53 | my $ni_res = request( $t->delete( url => '/actions/not_implemented' ) ); |
54 | is( $ni_res->code, 200, "Custom not_implemented handler succeeded" ); |
55 | is( |
56 | $ni_res->content, |
57 | "Not Implemented Handler", |
58 | "not_implemented handler had proper response" |
59 | ); |
60 | |
61 | 1; |