[Catalyst-dev] Catalyst::Test and POSTing non-form data
Rafael Kitover
rkitover at io.com
Mon Aug 18 14:26:08 BST 2008
When I was writing tests for my C::C::REST stuff, I noticed that posting
stuff only worked if I set CATALYST_SERVER.
Here's a patch with a failing test:
Index: t/live_engine_request_body.t
===================================================================
--- t/live_engine_request_body.t (revision 8230)
+++ t/live_engine_request_body.t (working copy)
@@ -6,12 +6,13 @@
use FindBin;
use lib "$FindBin::Bin/lib";
-use Test::More tests => 18;
+use Test::More tests => 21;
use Catalyst::Test 'TestApp';
use Catalyst::Request;
use HTTP::Headers;
use HTTP::Request::Common;
+use HTTP::Request ();
{
my $creq;
@@ -75,3 +76,15 @@
is( $creq->content_length, $request->content_length,
'Catalyst::Request Content-Length' );
}
+
+{
+ my $request = HTTP::Request->new(POST => '/body');
+
+ $request->header('Content-Type' => 'text/xml');
+ $request->content('<item>chainsaw</item>');
+
+ ok( my $response = request($request), 'Request' );
+ ok( $response->is_success, 'Response Successful 2xx' );
+
+ is( $response->content, '<item>chainsaw</item>', '$c->req->body is
set' );
+}
Index: t/lib/TestApp/Controller/Body.pm
===================================================================
--- t/lib/TestApp/Controller/Body.pm (revision 0)
+++ t/lib/TestApp/Controller/Body.pm (revision 0)
@@ -0,0 +1,13 @@
+package TestApp::Controller::Body;
+
+use strict;
+use warnings;
+use base 'Catalyst::Controller';
+
+sub dump_body : Path Args(0) {
+ my ( $self, $c ) = @_;
+
+ $c->res->body($c->req->body);
+}
+
+1;
More information about the Catalyst-dev
mailing list