X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fcatalyst-action-serialize-accept.t;h=13dead90a65e6d42f2ad76a571430507a1485f21;hb=2f7533ed98d3c3821696968844cbe4ff12159490;hp=176c5e9ae4ce813530f73b8bc7e08a987c61ab30;hpb=e601addaf89882fccbc824c1a53328f0d049b32b;p=catagits%2FCatalyst-Action-REST.git diff --git a/t/catalyst-action-serialize-accept.t b/t/catalyst-action-serialize-accept.t index 176c5e9..13dead9 100644 --- a/t/catalyst-action-serialize-accept.t +++ b/t/catalyst-action-serialize-accept.t @@ -14,9 +14,11 @@ use Catalyst; __PACKAGE__->config( name => 'Test::Catalyst::Action::Serialize', serialize => { + 'default' => 'text/x-yaml', 'stash_key' => 'rest', 'map' => { 'text/x-yaml' => 'YAML', + 'application/json' => 'JSON', 'text/x-data-dumper' => [ 'Data::Serializer', 'Data::Dumper' ], 'text/broken' => 'Broken', }, @@ -43,7 +45,7 @@ package main; use strict; use warnings; -use Test::More qw(no_plan); +use Test::More tests => 10; use Data::Serializer; use FindBin; use Data::Dump qw(dump); @@ -56,15 +58,53 @@ my $t = Test::Rest->new('content_type' => 'text/x-yaml'); use_ok 'Catalyst::Test', 'Test::Catalyst::Action::Serialize'; -my $req = $t->get(url => '/test'); -$req->remove_header('Content-Type'); -$req->header('Accept', 'text/x-yaml'); -my $res = request($req); -ok( $res->is_success, 'GET the serialized request succeeded' ); my $data = <content, $data, "Request returned proper data"); + +{ + my $req = $t->get(url => '/test'); + $req->remove_header('Content-Type'); + $req->header('Accept', 'text/x-yaml'); + my $res = request($req); + SKIP: { + skip "can't test text/x-yaml without YAML support", + 3 if ( + not $res->is_success and + $res->content =~ m#Content-Type text/x-yaml is not supported# + ); + ok( $res->is_success, 'GET the serialized request succeeded' ); + is( $res->content, $data, "Request returned proper data"); + is( $res->header('Content-type'), 'text/x-yaml', '... with expected content-type') + + }; +} + +SKIP: { + eval 'require JSON'; + skip "can't test application/json without JSON support", 3 if $@; + my $json = JSON->new; + my $at = Test::Rest->new('content_type' => 'text/doesnt-exist'); + my $req = $at->get(url => '/test'); + $req->header('Accept', 'application/json'); + my $res = request($req); + ok( $res->is_success, 'GET the serialized request succeeded' ); + my $ret = $json->decode($res->content); + is( $ret->{lou}, 'is my cat', "Request returned proper data"); + is( $res->header('Content-type'), 'application/json', 'Accept header used if content-type mapping not found') +}; + +# Make sure we don't get a bogus content-type when using default +# serializer (rt.cpan.org ticket 27949) +{ + my $req = $t->get(url => '/test'); + $req->remove_header('Content-Type'); + $req->header('Accept', '*/*'); + my $res = request($req); + ok( $res->is_success, 'GET the serialized request succeeded' ); + is( $res->content, $data, "Request returned proper data"); + is( $res->header('Content-type'), 'text/x-yaml', '... with expected content-type') +} 1;