
rkitover at io
Aug 18, 2008, 6:26 AM
Post #1 of 5
(1620 views)
Permalink
|
|
Catalyst::Test and POSTing non-form data
|
|
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; _______________________________________________ Catalyst-dev mailing list Catalyst-dev [at] lists http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst-dev
|