X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=t%2Fcatalyst-action-serialize.t;h=aa62651f064d1f2048f679d7e084c89d7c52ab58;hb=671b3a1fd09c29ad689a01a73c37fe299492830e;hp=7a3dbe331bc6f2fe51dd485dc6922cc05f3fca01;hpb=6646fdc27add35e5421e516b1fcd98560bef0b96;p=catagits%2FCatalyst-Action-REST.git diff --git a/t/catalyst-action-serialize.t b/t/catalyst-action-serialize.t index 7a3dbe3..aa62651 100644 --- a/t/catalyst-action-serialize.t +++ b/t/catalyst-action-serialize.t @@ -1,53 +1,9 @@ -package Test::Catalyst::Action::Serialize; - -use FindBin; - -use lib ("$FindBin::Bin/../lib"); - use strict; use warnings; -use Catalyst::Runtime '5.70'; - -use Catalyst; - -__PACKAGE__->config( - name => 'Test::Catalyst::Action::Serialize', - serialize => { - 'default' => 'YAML', - 'stash_key' => 'rest', - 'map' => { - 'text/x-yaml' => 'YAML', - 'text/x-data-dumper' => [ 'Data::Serializer', 'Data::Dumper' ], - 'text/broken' => 'Broken', - }, - } -); - -__PACKAGE__->setup; - -sub test :Local :ActionClass('Serialize') { - my ( $self, $c ) = @_; - $c->stash->{'rest'} = { - lou => 'is my cat', - }; -} - -sub test_second :Local :ActionClass('Serialize') { - my ( $self, $c ) = @_; - $c->stash->{'rest'} = { - lou => 'is my cat', - }; -} - -package main; - -use strict; -use warnings; -use Test::More tests => 7; +use Test::More 0.88; use Data::Serializer; use FindBin; -use Data::Dump qw(dump); use lib ("$FindBin::Bin/lib", "$FindBin::Bin/../lib", "$FindBin::Bin/broken"); use Test::Rest; @@ -55,25 +11,38 @@ use Test::Rest; # Should use Data::Dumper, via YAML my $t = Test::Rest->new('content_type' => 'text/x-data-dumper'); -use_ok 'Catalyst::Test', 'Test::Catalyst::Action::Serialize'; +use_ok 'Catalyst::Test', 'Test::Catalyst::Action::REST'; -my $res = request($t->get(url => '/test')); +my $res = request($t->get(url => '/serialize/test')); ok( $res->is_success, 'GET the serialized request succeeded' ); is( $res->content, "{'lou' => 'is my cat'}", "Request returned proper data"); my $nt = Test::Rest->new('content_type' => 'text/broken'); -my $bres = request($nt->get(url => '/test')); +my $bres = request($nt->get(url => '/serialize/test')); is( $bres->code, 415, 'GET on un-useable Serialize class returns 415'); my $ut = Test::Rest->new('content_type' => 'text/not-happening'); -my $ures = request($ut->get(url => '/test')); +my $ures = request($ut->get(url => '/serialize/test')); is ($bres->code, 415, 'GET on unknown Content-Type returns 415'); # This check is to make sure we can still serialize after the first # request. -my $res2 = request($t->get(url => '/test_second')); +my $res2 = request($t->get(url => '/serialize/test_second')); ok( $res2->is_success, '2nd request succeeded' ); is( $res2->content, "{'lou' => 'is my cat'}", "2nd request returned proper data"); +Test::Catalyst::Action::REST->controller('Serialize')->{serialize} = {}; +$res2 = request($t->get(url => '/serialize/test_second')); +ok( $res2->is_success, 'request succeeded (deprecated config)' ); +is( $res2->content, "{'lou' => 'is my cat'}", "request returned proper data"); + + +$res = request($t->get(url => '/serialize/empty_serialized')); +is $res->content, q[{'foo' => 'bar'}], 'normal case ok'; +ok $res->header('Content-Length'), 'set content-length when we serialize'; + +$res = request($t->get(url => '/serialize/empty_not_serialized_blank')); +is $res->content, '', "body explicitly set to '' results in '' content"; +ok !$res->header('Content-Length'), "body explicitly set to '' - no automatic content-length"; -1; +done_testing;