Subject: | Args(0) regression with ActionRole::MatchRequestAccepts |
When using ActionRole::MatchRequestAccepts, the fallback action takes precedence over any actions with Accept() if it has Args(0) instead of Args. The tests for ActionRole::MatchRequestAccepts don't catch this because they specify Args for the fallback, not Args(0). I noticed this behaviour in an internal work app.
The problem may be best demonstrated by the attached example test case, which fails from 09914a4 onward. 5.90084 is the last known good release, and bisect confirmed this. Note that the test case will pass if you change not_accepted's Args(0) to Args.
I think Catalyst is probably to blame here rather than ActionRole::MatchRequestAccepts, but let me know if I'm wrong and should report this regression over there instead.
Subject: | args0-match-request-accepts.t |
use warnings;
use strict;
use Test::More;
plan skip_all => 'Requires Catalyst::ActionRole::MatchRequestAccepts'
unless eval { require Catalyst::ActionRole::MatchRequestAccepts };
{
package MyApp::Controller::Root;
$INC{'MyApp/Controller/Root.pm'} = __FILE__;
use Moose;
use MooseX::MethodAttributes;
BEGIN { extends 'Catalyst::Controller' };
sub root : Chained('/') PathPrefix CaptureArgs(0) {}
sub text_plain : Chained('root') PathPart('') Does(MatchRequestAccepts) Accept('text/plain') Args(0) {
my ($self, $ctx) = @_;
$ctx->response->body('text_plain');
}
sub json : Chained('root') PathPart('') Does(MatchRequestAccepts) Accept('application/json') Args(0) {
my ($self, $ctx) = @_;
$ctx->response->body('json');
}
sub not_accepted : Chained('root') PathPart('') Args(0) {
my ($self, $ctx) = @_;
$ctx->response->body('error_not_accepted');
}
MyApp::Controller::Root->config(namespace=>'');
package MyApp;
use Catalyst;
MyApp->setup;
}
use Catalyst::Test 'MyApp';
use HTTP::Request::Common qw/GET/;
is request(GET '/')->content, 'error_not_accepted';
is request(GET '/', 'Accept' => 'text/plain')->content, 'text_plain';
is request(GET '/', 'Accept' => 'application/json')->content, 'json';
done_testing;