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