unmark +x and remove shebangs
[catagits/Catalyst-Runtime.git] / t / data_handler.t
CommitLineData
e2aa4a21 1use warnings;
2use strict;
3
4use FindBin;
5use Test::More;
6use HTTP::Request::Common;
7use JSON::MaybeXS;
8
9use lib "$FindBin::Bin/lib";
10use Catalyst::Test 'TestDataHandlers';
11
12ok my($res, $c) = ctx_request('/');
3eba0dd5 13
14{
15 ok my $message = 'helloworld';
16 ok my $post = encode_json +{message=>$message};
17 ok my $req = POST $c->uri_for_action('/test_json'),
18 Content_Type => 'application/json',
19 Content => $post;
20
21 ok my $response = request $req, 'got a response from a catalyst controller';
22 is $response->content, $message, 'expected content body';
23}
24
25{
26 ok my $req = POST $c->uri_for_action('/test_nested_for'), [ 'nested.value' => 'expected' ];
27 ok my $response = request $req, 'got a response from a catalyst controller';
28 is $response->content, 'expected', 'expected content body';
29}
30
c63ec19d 31{
32 my $out;
33 local *STDERR;
34 open(STDERR, ">", \$out) or die "Can't open STDERR: $!";
35 ok my $req = POST $c->uri_for_action('/test_nested_for'), 'Content-Type' => 'multipart/form-data', Content => { die => "a horrible death" };
36 ok my $response = request $req;
37 is($out, "[error] multipart/form-data does not have an available data handler. Valid data_handlers are application/json, application/x-www-form-urlencoded.\n", 'yep we throw the slightly more usefull error');
38}
e2aa4a21 39
40done_testing;