Commit | Line | Data |
e601adda |
1 | use strict; |
2 | use warnings; |
ad995b48 |
3 | |
786c212f |
4 | use Test::More 0.88; |
e601adda |
5 | use Data::Serializer; |
6 | use FindBin; |
e601adda |
7 | |
8 | use lib ("$FindBin::Bin/lib", "$FindBin::Bin/../lib", "$FindBin::Bin/broken"); |
9 | use Test::Rest; |
10 | |
1bb213fc |
11 | my $t = Test::Rest->new('content_type' => 'application/json'); |
e601adda |
12 | |
9d3bee45 |
13 | use_ok 'Catalyst::Test', 'Test::Catalyst::Action::REST'; |
e601adda |
14 | |
9d3bee45 |
15 | my $res = request($t->get(url => '/serialize/test')); |
e601adda |
16 | ok( $res->is_success, 'GET the serialized request succeeded' ); |
1bb213fc |
17 | is( $res->content, '{"lou":"is my cat"}', "Request returned proper data"); |
e601adda |
18 | |
19 | my $nt = Test::Rest->new('content_type' => 'text/broken'); |
9d3bee45 |
20 | my $bres = request($nt->get(url => '/serialize/test')); |
e601adda |
21 | is( $bres->code, 415, 'GET on un-useable Serialize class returns 415'); |
22 | |
23 | my $ut = Test::Rest->new('content_type' => 'text/not-happening'); |
9d3bee45 |
24 | my $ures = request($ut->get(url => '/serialize/test')); |
e601adda |
25 | is ($bres->code, 415, 'GET on unknown Content-Type returns 415'); |
26 | |
27 | # This check is to make sure we can still serialize after the first |
28 | # request. |
9d3bee45 |
29 | my $res2 = request($t->get(url => '/serialize/test_second')); |
e601adda |
30 | ok( $res2->is_success, '2nd request succeeded' ); |
1bb213fc |
31 | is( $res2->content,'{"lou":"is my cat"}', "2nd request returned proper data"); |
e601adda |
32 | |
7b8c5be2 |
33 | Test::Catalyst::Action::REST->controller('Serialize')->{serialize} = {}; |
34 | $res2 = request($t->get(url => '/serialize/test_second')); |
35 | ok( $res2->is_success, 'request succeeded (deprecated config)' ); |
1bb213fc |
36 | is( $res2->content,'{"lou":"is my cat"}', "request returned proper data"); |
e601adda |
37 | |
467b1ade |
38 | |
786c212f |
39 | $res = request($t->get(url => '/serialize/empty_serialized')); |
1bb213fc |
40 | is $res->content, q[{"foo":"bar"}], 'normal case ok'; |
786c212f |
41 | ok $res->header('Content-Length'), 'set content-length when we serialize'; |
42 | |
786c212f |
43 | $res = request($t->get(url => '/serialize/empty_not_serialized_blank')); |
44 | is $res->content, '', "body explicitly set to '' results in '' content"; |
45 | ok !$res->header('Content-Length'), "body explicitly set to '' - no automatic content-length"; |
46 | |
fb9d509b |
47 | $res = request($t->get(url => '/serialize/explicit_view')); |
48 | is $res->content, '', "view explicitly set to '' results in '' content"; |
49 | ok !$res->header('Content-Length'), "view explicitly set to '' - no automatic content-length"; |
50 | |
786c212f |
51 | done_testing; |