From: Mark Ellis Date: Wed, 7 May 2014 17:46:53 +0000 (+0100) Subject: Merge remote-tracking branch 'origin/master' into ancona X-Git-Tag: 5.90070~29 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=0104ba44ac3abe1c816d673334eca9d46305a8f0;hp=-c Merge remote-tracking branch 'origin/master' into ancona --- 0104ba44ac3abe1c816d673334eca9d46305a8f0 diff --combined t/psgi_utils.t index bbdb2ad,15afb9d..078dd82 --- a/t/psgi_utils.t +++ b/t/psgi_utils.t @@@ -3,17 -3,40 +3,40 @@@ use strict # Make it easier to mount PSGI apps under catalyst + my $psgi_app = sub { + my $req = Plack::Request->new(shift); + return [200,[],[$req->path]]; + }; + { - package MyApp::Controller::User; + package MyApp::Controller::Docs; + $INC{'MyApp/Controller/Docs.pm'} = __FILE__; use base 'Catalyst::Controller'; use Plack::Request; use Catalyst::Utils; - my $psgi_app = sub { - my $req = Plack::Request->new(shift); - return [200,[],[$req->path]]; - }; + sub name :Local { + my ($self, $c) = @_; + my $env = $c->Catalyst::Utils::env_at_action; + $c->res->from_psgi_response( + $psgi_app->($env)); + + } + + sub name_args :Local Args(1) { + my ($self, $c, $arg) = @_; + my $env = $c->Catalyst::Utils::env_at_action; + $c->res->from_psgi_response( + $psgi_app->($env)); + } + + package MyApp::Controller::User; + $INC{'MyApp/Controller/User.pm'} = __FILE__; + + use base 'Catalyst::Controller'; + use Plack::Request; + use Catalyst::Utils; sub local_example :Local { my ($self, $c) = @_; @@@ -54,27 -77,6 +77,27 @@@ $c->res->from_psgi_response( $psgi_app->($env)); } + + sub mounted :Local Args(1) { + my ($self, $c, $arg) = @_; + our $app ||= ref($c)->psgi_app; + my $env = $self->get_env($c); + $c->res->from_psgi_response( + $app->($env)); + } + + sub mount_arg :Path(/mounted) Arg(1) { + my ($self, $c, $arg) = @_; + my $uri = $c->uri_for( $self->action_for('local_example_args1'),$arg); + $c->res->body("$uri"); + } + + sub mount_noarg :Path(/mounted_no_arg) { + my ($self, $c) = @_; + my $uri = $c->uri_for( $self->action_for('local_example_args1'),444); + $c->res->body("$uri"); + } + sub get_env { my ($self, $c) = @_; @@@ -89,8 -91,6 +112,6 @@@ } } - $INC{'MyApp/Controller/User.pm'} = __FILE__; - package MyApp; use Catalyst; MyApp->setup; @@@ -100,20 -100,6 +121,20 @@@ use Test::More; use Catalyst::Test 'MyApp'; +{ + my ($res, $c) = ctx_request('/user/mounted/111?path_prefix=1'); + is $c->action, 'user/mounted'; + is $res->content, 'http://localhost/user/user/local_example_args1/111'; + is_deeply $c->req->args, [111]; +} + +{ + my ($res, $c) = ctx_request('/user/mounted/mounted_no_arg?env_path=1'); + is $c->action, 'user/mounted'; + is $res->content, 'http://localhost/user/mounted/user/local_example_args1/444'; + is_deeply $c->req->args, ['mounted_no_arg']; +} + # BEGIN [user/local_example] { my ($res, $c) = ctx_request('/user/local_example'); @@@ -324,6 -310,26 +345,26 @@@ is_deeply $c->req->args, [444]; } + { + my ($res, $c) = ctx_request('/docs/name'); + is $c->action, 'docs/name'; + is $res->content, '/'; + is_deeply $c->req->args, []; + } + + { + my ($res, $c) = ctx_request('/docs/name/111/222'); + is $c->action, 'docs/name'; + is $res->content, '/111/222'; + is_deeply $c->req->args, [111,222]; + } + + { + my ($res, $c) = ctx_request('/docs/name_args/111'); + is $c->action, 'docs/name_args'; + is $res->content, '/111'; + is_deeply $c->req->args, [111]; + } done_testing();