[Catalyst-commits] r11816 - in
Catalyst-Runtime/5.80/branches/action_args/t: aggregate
lib/TestApp/Action lib/TestApp/Controller/Action
rafl at dev.catalyst.perl.org
rafl at dev.catalyst.perl.org
Fri Nov 13 14:49:25 GMT 2009
Author: rafl
Date: 2009-11-13 14:49:21 +0000 (Fri, 13 Nov 2009)
New Revision: 11816
Added:
Catalyst-Runtime/5.80/branches/action_args/t/lib/TestApp/Action/TestExtraArgsAction.pm
Modified:
Catalyst-Runtime/5.80/branches/action_args/t/aggregate/live_component_controller_action_action.t
Catalyst-Runtime/5.80/branches/action_args/t/lib/TestApp/Controller/Action/Action.pm
Log:
Add tests for passing extra arguments to action constructors.
Modified: Catalyst-Runtime/5.80/branches/action_args/t/aggregate/live_component_controller_action_action.t
===================================================================
--- Catalyst-Runtime/5.80/branches/action_args/t/aggregate/live_component_controller_action_action.t 2009-11-13 14:47:56 UTC (rev 11815)
+++ Catalyst-Runtime/5.80/branches/action_args/t/aggregate/live_component_controller_action_action.t 2009-11-13 14:49:21 UTC (rev 11816)
@@ -10,7 +10,7 @@
BEGIN { $iters = $ENV{CAT_BENCH_ITERS} || 1; }
-use Test::More tests => 42 * $iters;
+use Test::More;
use Catalyst::Test 'TestApp';
if ( $ENV{CAT_BENCHMARK} ) {
@@ -147,4 +147,25 @@
);
}
+ {
+ ok( my $response = request('http://localhost/action_action_seven'),
+ '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_seven', 'Test Action' );
+ is(
+ $response->header('X-Test-Class'),
+ 'TestApp::Controller::Action::Action',
+ 'Test Class'
+ );
+ is( $response->header('X-TestExtraArgsAction'), '42,23', 'Extra args get passed to action contstructor' );
+ like(
+ $response->content,
+ qr/^bless\( .* 'Catalyst::Request' \)$/s,
+ 'Content is a serialized Catalyst::Request'
+ );
+ }
}
+
+done_testing;
Added: Catalyst-Runtime/5.80/branches/action_args/t/lib/TestApp/Action/TestExtraArgsAction.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/action_args/t/lib/TestApp/Action/TestExtraArgsAction.pm (rev 0)
+++ Catalyst-Runtime/5.80/branches/action_args/t/lib/TestApp/Action/TestExtraArgsAction.pm 2009-11-13 14:49:21 UTC (rev 11816)
@@ -0,0 +1,17 @@
+package TestApp::Action::TestExtraArgsAction;
+
+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;
Modified: Catalyst-Runtime/5.80/branches/action_args/t/lib/TestApp/Controller/Action/Action.pm
===================================================================
--- Catalyst-Runtime/5.80/branches/action_args/t/lib/TestApp/Controller/Action/Action.pm 2009-11-13 14:47:56 UTC (rev 11815)
+++ Catalyst-Runtime/5.80/branches/action_args/t/lib/TestApp/Controller/Action/Action.pm 2009-11-13 14:49:21 UTC (rev 11816)
@@ -3,7 +3,15 @@
use strict;
use base 'TestApp::Controller::Action';
-__PACKAGE__->config( actions => { action_action_five => { ActionClass => '+Catalyst::Action::TestBefore' } } );
+__PACKAGE__->config(
+ actions => {
+ action_action_five => { ActionClass => '+Catalyst::Action::TestBefore' },
+ },
+ action_args => {
+ '*' => { extra_arg => 42 },
+ action_action_seven => { another_extra_arg => 23 },
+ },
+);
sub action_action_one : Global : ActionClass('TestBefore') {
my ( $self, $c ) = @_;
@@ -38,4 +46,9 @@
$c->forward('TestApp::View::Dump::Request');
}
+sub action_action_seven : Global : ActionClass('~TestExtraArgsAction') {
+ my ( $self, $c ) = @_;
+ $c->forward('TestApp::View::Dump::Request');
+}
+
1;
More information about the Catalyst-commits
mailing list