Commit | Line | Data |
e601adda |
1 | use strict; |
2 | use warnings; |
ad995b48 |
3 | |
786c212f |
4 | use Test::More 0.88; |
801ec379 |
5 | use Test::Requires qw(YAML::Syck); |
e601adda |
6 | use FindBin; |
e601adda |
7 | |
8 | use lib ("$FindBin::Bin/lib", "$FindBin::Bin/../lib", "$FindBin::Bin/broken"); |
9 | use Test::Rest; |
10 | |
81b9fff3 |
11 | my $t = Test::Rest->new('content_type' => 'text/x-yaml'); |
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' ); |
81b9fff3 |
17 | is( $res->content, "--- \nlou: is my cat\n", "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' ); |
81b9fff3 |
31 | is( $res2->content, "--- \nlou: is my cat\n", "request returned proper data"); |
e601adda |
32 | |
81b9fff3 |
33 | Test::Catalyst::Action::REST->controller('Serialize')->{serialize} = { }; |
7b8c5be2 |
34 | $res2 = request($t->get(url => '/serialize/test_second')); |
35 | ok( $res2->is_success, 'request succeeded (deprecated config)' ); |
81b9fff3 |
36 | is( $res2->content, "--- \nlou: is my cat\n", "request returned proper data"); |
e601adda |
37 | |
467b1ade |
38 | |
786c212f |
39 | $res = request($t->get(url => '/serialize/empty_serialized')); |
81b9fff3 |
40 | is $res->content, "--- \nfoo: bar\n", '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; |