Fix display of foo_GET mehods in non-root controllers
[catagits/Catalyst-Action-REST.git] / t / catalyst-action-rest-action-dispatch.t
1 use strict;
2 use warnings;
3 use Test::More 0.88;
4 use FindBin;
5 use Data::Dumper;
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 $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"
44         );
45     }
46 }
47
48 my $res = request(
49     $t->put(
50         url  => '/actions/test',
51         data => '',
52     )
53 );
54 is(
55     $res->header('Using-Action'),
56     'STATION',
57     "went through action for dispatching to PUT"
58 );
59 is(
60     $res->header('Using-Sub-Action'),
61     'MOO',
62     "went through sub action for dispatching to PUT"
63 );
64
65 done_testing;