Add failing tests for default HEAD dispatch
[catagits/Catalyst-Action-REST.git] / t / catalyst-action-rest-action-dispatch.t
CommitLineData
7656dd12 1use strict;
2use warnings;
5213846d 3use Test::More 0.88;
7656dd12 4use FindBin;
3c4306f2 5use Data::Dumper;
7656dd12 6use lib ( "$FindBin::Bin/lib", "$FindBin::Bin/../lib" );
7use Test::Rest;
8
9# Should use the default serializer, YAML
10my $t = Test::Rest->new( 'content_type' => 'text/plain' );
11
12use_ok 'Catalyst::Test', 'Test::Catalyst::Action::REST';
13
3c4306f2 14foreach 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 48my $head_res = request( $t->head(url => '/actions/test') );
49ok($head_res->is_success, 'HEAD request succeeded')
50 or diag($head_res->code);
51ok(!$head_res->content, 'HEAD request had proper response');
52
5213846d 53my $res = request(
54 $t->put(
55 url => '/actions/test',
56 data => '',
57 )
58);
59is(
60 $res->header('Using-Action'),
61 'STATION',
62 "went through action for dispatching to PUT"
63);
64is(
65 $res->header('Using-Sub-Action'),
66 'MOO',
67 "went through sub action for dispatching to PUT"
68);
69
70done_testing;