Release commit for 5.90128
[catagits/Catalyst-Runtime.git] / t / consumes.t
1 use warnings;
2 use strict;
3 use Test::More;
4
5 # Test case for reported issue when an action consumes JSON but a
6 # POST sends nothing we get a hard error
7
8 {
9   package MyApp::Controller::Root;
10   $INC{'MyApp/Controller/Root.pm'} = __FILE__;
11
12   use base 'Catalyst::Controller';
13
14   sub bar :Local Args(0) POST Consumes(JSON) {
15     my( $self, $c ) = @_;
16     my $foo = $c->req->body_data;
17   }
18
19   sub end :Private {
20     my( $self, $c ) = @_;
21     my $body = $c->shift_errors;
22     $c->res->body( $body || "No errors");
23   }
24
25   package MyApp;
26   use Catalyst;
27   MyApp->setup;
28 }
29
30 use HTTP::Request::Common;
31 use Catalyst::Test 'MyApp';
32
33 {
34   # Test to send no post
35   ok my $res = request POST 'root/bar',
36     'Content-Type' => 'application/json';
37
38   like $res->content, qr"Error Parsing POST 'undef'";
39 }
40
41 {
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';
46
47   like $res->content, qr/Error Parsing POST 'i am not JSON'/;
48 }
49
50 {
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" }';
55
56   is $res->content, 'No errors';
57 }
58
59 done_testing();