parameters are now being properly passed to the sub request
Eden Cardim [Thu, 19 Jul 2012 03:39:54 +0000 (03:39 +0000)]
lib/Catalyst/Plugin/SubRequest.pm
t/02subreq.t
t/lib/TestApp/Controller/Root.pm

index 032293e..433ebb9 100644 (file)
@@ -2,6 +2,7 @@ package Catalyst::Plugin::SubRequest;
 
 use strict;
 use warnings;
+use Plack::Request;
 
 our $VERSION = '0.18';
 
@@ -85,6 +86,10 @@ sub sub_request_response {
     my ( $c, $path, $stash, $params ) = @_;
     $stash ||= {};
     my $env = $c->request->env;
+    my $req = Plack::Request->new($env);
+    my $uri = $req->uri;
+    $uri->query_form($params||{});
+    $env->{QUERY_STRING} = $uri->query||'';
     local $env->{PATH_INFO} = $path;
     local $env->{REQUEST_URI} = $env->{SCRIPT_NAME} . $path;
     $env->{REQUEST_URI} =~ s|//|/|g;
index 85050eb..ce90f22 100644 (file)
@@ -1,6 +1,6 @@
 package main;
 
-use Test::More tests => 15;
+use Test::More tests => 18;
 use lib 't/lib';
 use Catalyst::Test 'TestApp';
 use File::stat;
@@ -38,3 +38,8 @@ my $stat = stat($0);
     is( $response->content, '1text/csv3',    'Normal request content', );
 }
 
+{
+    ok( my $response = request('/subtest_with_params'),    'Sub request with full params'  );
+    is( $response->code, 200,                 'OK status code'  );
+    is( $response->content, 'foo33',    'Normal request content', );
+}
index 35af79a..4f21132 100644 (file)
@@ -42,6 +42,18 @@ sub subtest_full_response : Global {
     $c->res->body( $c->res->body() . $subreq_res->content_type );
 }
 
+sub subtest_with_params :Global {
+  my($self, $c) = @_;
+  $c->res->body(
+    $c->subrequest('/plain_param', {},
+      { content => 'foo' }));
+}
+
+sub plain_param :Global {
+  my($self, $c) = @_;
+  $c->res->body($c->req->params->{content});
+}
+
 sub typesetter : Global {
     my ( $self, $c, $arg ) = @_;
     $c->res->content_type( 'text/csv' );