X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fcatalyst-action-rest-action-dispatch.t;h=8d0139895b2800f29a5d4be218380ee663cc121f;hb=3ba4e173c6929eb2cbb3b0c8c15449693703bbf5;hp=93ffb17e2d9f8b48eec912537dbc0765e80fc20a;hpb=7656dd125be1895119fad6495083c29599deac44;p=catagits%2FCatalyst-Action-REST.git diff --git a/t/catalyst-action-rest-action-dispatch.t b/t/catalyst-action-rest-action-dispatch.t index 93ffb17..8d01398 100644 --- a/t/catalyst-action-rest-action-dispatch.t +++ b/t/catalyst-action-rest-action-dispatch.t @@ -1,8 +1,8 @@ use strict; use warnings; -use Test::More tests => 23; +use Test::More 0.88; use FindBin; - +use Data::Dumper; use lib ( "$FindBin::Bin/lib", "$FindBin::Bin/../lib" ); use Test::Rest; @@ -11,51 +11,60 @@ my $t = Test::Rest->new( 'content_type' => 'text/plain' ); use_ok 'Catalyst::Test', 'Test::Catalyst::Action::REST'; -foreach my $method (qw(GET DELETE POST PUT OPTIONS)) { - my $run_method = lc($method); - my $result = "something $method"; - my $res; - if ( grep /$method/, qw(GET DELETE OPTIONS) ) { - $res = request( $t->$run_method( url => '/actions/test' ) ); - } else { - $res = request( - $t->$run_method( - url => '/actions/test', - data => '', - ) +foreach my $endpoint (qw/ test other_test /) { + foreach my $method (qw(GET DELETE POST PUT OPTIONS)) { + my $run_method = lc($method); + my $res; + if ( grep /$method/, qw(GET DELETE OPTIONS) ) { + $res = request( $t->$run_method( url => '/actions/' . $endpoint ) ); + } + else { + $res = request( + $t->$run_method( + url => '/actions/' . $endpoint, + data => '', + ) + ); + } + ok( $res->is_success, "$method request succeeded" ) or warn Dumper($res); + is( + $res->content, + "$method", + "$method request had proper response" + ); + is( + $res->header('X-Was-In-TopLevel'), + '1', + "went through top level action for dispatching to $method" + ); + is( + $res->header('Using-Action'), + 'STATION', + "went through action for dispatching to $method" ); } - ok( $res->is_success, "$method request succeeded" ); - is( - $res->content, - "something $method", - "$method request had proper response" - ); - is( - $res->header('Using-Action'), - 'STATION', - "went through action for dispatching to $method" - ); } -my $fail_res = request( $t->delete( url => '/actions/notreally' ) ); -is( $fail_res->code, 405, "Request to bad method gets 405 Not Implemented" ); -is( $fail_res->header('allow'), "GET", "405 allow header properly set." ); - -my $options_res = request( $t->options( url => '/actions/notreally' ) ); -is( $options_res->code, 200, "OPTIONS request handler succeeded" ); -is( $options_res->header('allow'), - "GET", "OPTIONS request allow header properly set." ); +my $head_res = request( $t->head(url => '/actions/test') ); +ok($head_res->is_success, 'HEAD request succeeded') + or diag($head_res->code); +ok(!$head_res->content, 'HEAD request had proper response'); -my $modified_res = request( $t->get( url => '/actions/not_modified' ) ); -is( $modified_res->code, 304, "Not Modified request handler succeeded" ); - -my $ni_res = request( $t->delete( url => '/actions/not_implemented' ) ); -is( $ni_res->code, 200, "Custom not_implemented handler succeeded" ); +my $res = request( + $t->put( + url => '/actions/test', + data => '', + ) +); +is( + $res->header('Using-Action'), + 'STATION', + "went through action for dispatching to PUT" +); is( - $ni_res->content, - "Not Implemented Handler", - "not_implemented handler had proper response" + $res->header('Using-Sub-Action'), + 'MOO', + "went through sub action for dispatching to PUT" ); -1; +done_testing;