Bugfix _dispatch_rest_method
Wallace Reis [Fri, 29 Jun 2012 11:57:36 +0000 (13:57 +0200)]
Code to action lookup key must be based on $rest_method instead of $req
info.

lib/Catalyst/Action/REST.pm
t/catalyst-action-rest.t
t/lib/Test/Catalyst/Action/REST/Controller/Actions.pm

index 34088ee..09a4deb 100644 (file)
@@ -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;
     }
index 124906c..6bfadd9 100644 (file)
@@ -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." );
index 86210fb..905b700 100644 (file)
@@ -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;