From: skaufman Date: Mon, 16 Apr 2012 17:22:58 +0000 (+0000) Subject: tests and patch for Controller to accept action_args from constructor X-Git-Tag: 5.90013~10 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=bf7c9c87ac809f8370ee21db7effef130ea6e058 tests and patch for Controller to accept action_args from constructor --- diff --git a/lib/Catalyst/Controller.pm b/lib/Catalyst/Controller.pm index 1442649..a6bba64 100644 --- a/lib/Catalyst/Controller.pm +++ b/lib/Catalyst/Controller.pm @@ -36,6 +36,8 @@ has actions => init_arg => undef, ); +has action_args => (is => 'ro'); + # ->config(actions => { '*' => ... has _all_actions_attributes => ( is => 'ro', @@ -279,7 +281,11 @@ sub create_action { my %args = @_; my $class = $self->action_class(%args); - my $action_args = $self->config->{action_args}; + my $action_args = ( + ref($self) + ? $self->action_args + : $self->config->{action_args} + ); my %extra_args = ( %{ $action_args->{'*'} || {} }, diff --git a/t/aggregate/live_component_controller_action_action.t b/t/aggregate/live_component_controller_action_action.t index bc2038e..eebfe48 100644 --- a/t/aggregate/live_component_controller_action_action.t +++ b/t/aggregate/live_component_controller_action_action.t @@ -193,6 +193,25 @@ sub run_tests { is_deeply $action->attributes->{extra_attribute}, [13]; is_deeply $action->attributes->{another_extra_attribute}, ['foo']; } + { + ok( my $response = request('http://localhost/action_action_nine'), + 'Request' ); + ok( $response->is_success, 'Response Successful 2xx' ); + is( $response->content_type, 'text/plain', 'Response Content-Type' ); + is( $response->header('X-Catalyst-Action'), + 'action_action_nine', 'Test Action' ); + is( + $response->header('X-Test-Class'), + 'TestApp::Controller::Action::Action', + 'Test Class' + ); + is( $response->header('X-TestExtraArgsAction'), '42,13', 'Extra args get passed to action constructor' ); + like( + $response->content, + qr/^bless\( .* 'Catalyst::Request' \)$/s, + 'Content is a serialized Catalyst::Request' + ); + } } done_testing; diff --git a/t/lib/TestApp.pm b/t/lib/TestApp.pm index 3bd3763..25203e1 100644 --- a/t/lib/TestApp.pm +++ b/t/lib/TestApp.pm @@ -1,5 +1,4 @@ package TestApp; - use strict; use Catalyst qw/ Test::MangleDollarUnderScore @@ -42,7 +41,16 @@ has 'my_greeting_obj_lazy' => ( our $VERSION = '0.01'; -TestApp->config( name => 'TestApp', root => '/some/dir', use_request_uri_for_path => 1 ); +TestApp->config( + name => 'TestApp', + root => '/some/dir', + use_request_uri_for_path => 1, + 'Controller::Action::Action' => { + action_args => { + action_action_nine => { another_extra_arg => 13 } + } + } +); # Test bug found when re-adjusting the metaclass compat code in Moose # in 292360. Test added to Moose in 4b760d6, but leave this attribute diff --git a/t/lib/TestApp/Action/TestActionArgsFromConstructor.pm b/t/lib/TestApp/Action/TestActionArgsFromConstructor.pm new file mode 100644 index 0000000..67f8a13 --- /dev/null +++ b/t/lib/TestApp/Action/TestActionArgsFromConstructor.pm @@ -0,0 +1,18 @@ +package TestApp::Action::TestActionArgsFromConstructor; + +use Moose; +use namespace::autoclean; + +extends 'Catalyst::Action'; + +has [qw/extra_arg another_extra_arg/] => ( is => 'ro' ); + +after execute => sub { + my ($self, $controller, $ctx) = @_; + $ctx->response->header('X-TestExtraArgsAction' => join q{,} => $self->extra_arg, $self->another_extra_arg); +}; + +__PACKAGE__->meta->make_immutable; + +1; + diff --git a/t/lib/TestApp/Controller/Action/Action.pm b/t/lib/TestApp/Controller/Action/Action.pm index 6cee5f5..515fb2a 100644 --- a/t/lib/TestApp/Controller/Action/Action.pm +++ b/t/lib/TestApp/Controller/Action/Action.pm @@ -58,4 +58,8 @@ sub action_action_eight : Global { $c->forward('TestApp::View::Dump::Action'); } +sub action_action_nine : Global : ActionClass('~TestActionArgsFromConstructor') { + my ( $self, $c ) = @_; + $c->forward('TestApp::View::Dump::Request'); +} 1;