5 # Test case for reported issue when an action consumes JSON but a
6 # POST sends nothing we get a hard error
9 package MyApp::Controller::Root;
10 $INC{'MyApp/Controller/Root.pm'} = __FILE__;
12 use base 'Catalyst::Controller';
14 sub bar :Local Args(0) POST Consumes(JSON) {
16 my $foo = $c->req->body_data;
21 my $body = $c->shift_errors;
22 $c->res->body( $body || "No errors");
30 use HTTP::Request::Common;
31 use Catalyst::Test 'MyApp';
34 # Test to send no post
35 ok my $res = request POST 'root/bar',
36 'Content-Type' => 'application/json';
38 like $res->content, qr"Error Parsing POST 'undef'";
42 # Test to send bad (malformed JSON) post
43 ok my $res = request POST 'root/bar',
44 'Content-Type' => 'application/json',
45 'Content' => 'i am not JSON';
47 like $res->content, qr/Error Parsing POST 'i am not JSON'/;
51 # Test to send bad (malformed JSON) post
52 ok my $res = request POST 'root/bar',
53 'Content-Type' => 'application/json',
54 'Content' => '{ "a":"b" }';
56 is $res->content, 'No errors';