added test case for parsing JSON and updated changlog
John Napiorkowski [Tue, 20 Aug 2013 16:01:43 +0000 (12:01 -0400)]
Changes
Makefile.PL
t/data_handler.t [new file with mode: 0644]
t/lib/TestDataHandlers.pm [new file with mode: 0644]
t/lib/TestDataHandlers/Controller/Root.pm [new file with mode: 0644]

diff --git a/Changes b/Changes
index bd99d01..8cdcf20 100644 (file)
--- 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".
index 45216cc..e561124 100644 (file)
@@ -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 (file)
index 0000000..26ce2f9
--- /dev/null
@@ -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 (file)
index 0000000..0c52778
--- /dev/null
@@ -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 (file)
index 0000000..42bf85b
--- /dev/null
@@ -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;