From: Wallace Reis Date: Fri, 29 Jun 2012 11:57:36 +0000 (+0200) Subject: Bugfix _dispatch_rest_method X-Git-Tag: 1.08~19 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Action-Serialize-Data-Serializer.git;a=commitdiff_plain;h=9e4398c862fc57d6f9d83f9c64ab3e5e858b9862 Bugfix _dispatch_rest_method Code to action lookup key must be based on $rest_method instead of $req info. --- diff --git a/lib/Catalyst/Action/REST.pm b/lib/Catalyst/Action/REST.pm index 34088ee..09a4deb 100644 --- a/lib/Catalyst/Action/REST.pm +++ b/lib/Catalyst/Action/REST.pm @@ -131,7 +131,9 @@ sub _dispatch_rest_method { || sub { $self->_return_not_implemented($self->name, @_) }; }, }; - my $respond = ($code_action->{$req->method} + my ( $http_method, $action_name ) = ( $rest_method, $self->name ); + $http_method =~ s{\Q$action_name\E\_}{}; + my $respond = ($code_action->{$http_method} || $code_action->{'default'})->(); return $respond unless $name; } diff --git a/t/catalyst-action-rest.t b/t/catalyst-action-rest.t index 124906c..6bfadd9 100644 --- a/t/catalyst-action-rest.t +++ b/t/catalyst-action-rest.t @@ -38,6 +38,10 @@ ok($head_res->is_success, 'HEAD request succeeded') or diag($head_res->code); ok(!$head_res->content, 'HEAD request had proper response'); +$head_res = request( $t->head(url => '/actions/yet_other_test') ); +ok($head_res->code == 405, 'HEAD request succeeded') + or diag($head_res->code); + my $fail_res = request( $t->delete( url => '/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." ); diff --git a/t/lib/Test/Catalyst/Action/REST/Controller/Actions.pm b/t/lib/Test/Catalyst/Action/REST/Controller/Actions.pm index 86210fb..905b700 100644 --- a/t/lib/Test/Catalyst/Action/REST/Controller/Actions.pm +++ b/t/lib/Test/Catalyst/Action/REST/Controller/Actions.pm @@ -70,6 +70,13 @@ sub other_test_OPTIONS { $c->res->body('OPTIONS'); } +sub yet_other_test : Local : ActionClass('+Catalyst::Action::REST') {} + +sub yet_other_test_POST { + my ( $self, $c ) = @_; + $c->res->body('POST'); +} + sub end : Private {} # Don't need serialization.. 1;