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