From: John Napiorkowski Date: Tue, 20 Aug 2013 16:01:43 +0000 (-0400) Subject: added test case for parsing JSON and updated changlog X-Git-Tag: 5.90050~1^2~46 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=e2aa4a2182ee4503a91c66b05ac9c3371e61ed5c added test case for parsing JSON and updated changlog --- diff --git a/Changes b/Changes index bd99d01..8cdcf20 100644 --- a/Changes +++ b/Changes @@ -1,5 +1,12 @@ # This file documents the revision history for Perl extension Catalyst. +5.90049_002 - 2013-08-20 + - Fixed loading middleware from project directory + - Fixed some pointless warnings when middleware class lacked VERSION + - NEW FEATURE: Declare global 'data_handlers' for parsing HTTP POST/PUT + alternative content, and created default JSON handler. Yes, now Catalyst + handles JSON request content out of the box! + 5.90049_001 - 2013-07-26 - Declare PSGI compliant Middleware as part of your Catalyst Application via a new configuration key, "psgi_middleware". diff --git a/Makefile.PL b/Makefile.PL index 45216cc..e561124 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -83,6 +83,7 @@ test_requires 'Data::Dump'; test_requires 'HTTP::Request::Common'; test_requires 'IO::Scalar'; test_requires 'HTTP::Status'; +test_requires 'JSON::MaybeXS'; # aggregate tests if AGGREGATE_TESTS is set and a recent Test::Aggregate and a Test::Simple it works with is available my @author_requires; diff --git a/t/data_handler.t b/t/data_handler.t new file mode 100644 index 0000000..26ce2f9 --- /dev/null +++ b/t/data_handler.t @@ -0,0 +1,24 @@ +#!/usr/bin/env perl + +use warnings; +use strict; + +use FindBin; +use Test::More; +use HTTP::Request::Common; +use JSON::MaybeXS; + +use lib "$FindBin::Bin/lib"; +use Catalyst::Test 'TestDataHandlers'; + +ok my($res, $c) = ctx_request('/'); +ok my $message = 'helloworld'; +ok my $post = encode_json +{message=>$message}; +ok my $req = POST $c->uri_for_action('/test_json'), + Content_Type => 'application/json', + Content => $post; + +ok my $response = request $req, 'got a response from a catalyst controller'; +is $response->content, $message, 'expected content body'; + +done_testing; diff --git a/t/lib/TestDataHandlers.pm b/t/lib/TestDataHandlers.pm new file mode 100644 index 0000000..0c52778 --- /dev/null +++ b/t/lib/TestDataHandlers.pm @@ -0,0 +1,9 @@ +package TestDataHandlers; + +use Catalyst; + +__PACKAGE__->config( + 'Controller::Root', { namespace => '' } +); + +__PACKAGE__->setup; diff --git a/t/lib/TestDataHandlers/Controller/Root.pm b/t/lib/TestDataHandlers/Controller/Root.pm new file mode 100644 index 0000000..42bf85b --- /dev/null +++ b/t/lib/TestDataHandlers/Controller/Root.pm @@ -0,0 +1,10 @@ +package TestDataHandlers::Controller::Root; + +use base 'Catalyst::Controller'; + +sub test_json :Local { + my ($self, $c) = @_; + $c->res->body($c->req->body_data->{message}); +} + +1;