From: Hans Dieter Pearcey Date: Wed, 25 Mar 2009 05:27:40 +0000 (-0400) Subject: refactor another single-file app X-Git-Tag: 0.67_01~10 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Action-REST.git;a=commitdiff_plain;h=74bc96b93609184ade74bd75a0a0a17fe8e4b374 refactor another single-file app --- diff --git a/t/catalyst-action-serialize-accept.t b/t/catalyst-action-serialize-accept.t index 90a4fe4..836a8e8 100644 --- a/t/catalyst-action-serialize-accept.t +++ b/t/catalyst-action-serialize-accept.t @@ -1,51 +1,3 @@ -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' => 'text/x-yaml', - 'stash_key' => 'rest', - 'content_type_stash_key' => 'serialize_content_type', - 'map' => { - 'text/x-yaml' => 'YAML', - 'application/json' => 'JSON', - '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->{'serialize_content_type'} = $c->req->params->{'serialize_content_type'}; - $c->stash->{'rest'} = { - lou => 'is my cat', - }; -} - - -package main; - use strict; use warnings; use Test::More tests => 16; @@ -59,7 +11,7 @@ use Test::Rest; # Should use Data::Dumper, via YAML my $t = Test::Rest->new('content_type' => 'text/x-yaml'); -use_ok 'Catalyst::Test', 'Test::Catalyst::Action::Serialize'; +use_ok 'Catalyst::Test', 'Test::Catalyst::Action::REST'; my $data = <get(url => '/test'); + my $req = $t->get(url => '/serialize/test'); $req->remove_header('Content-Type'); $req->header('Accept', 'text/x-yaml'); my $res = request($req); @@ -89,7 +41,7 @@ SKIP: { 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'); + my $req = $at->get(url => '/serialize/test'); $req->header('Accept', 'application/json'); my $res = request($req); ok( $res->is_success, 'GET the serialized request succeeded' ); @@ -101,7 +53,7 @@ SKIP: { # 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'); + my $req = $t->get(url => '/serialize/test'); $req->remove_header('Content-Type'); $req->header('Accept', '*/*'); my $res = request($req); @@ -112,7 +64,7 @@ SKIP: { # Make that using content_type_stash_key, an invalid value in the stash gets ignored { - my $req = $t->get(url => '/test_second?serialize_content_type=nonesuch'); + my $req = $t->get(url => '/serialize/test_second?serialize_content_type=nonesuch'); $req->remove_header('Content-Type'); $req->header('Accept', '*/*'); my $res = request($req); @@ -123,7 +75,9 @@ SKIP: { # Make that using content_type_stash_key, a valid value in the stash gets priority { - my $req = $t->get(url => '/test_second?serialize_content_type=text/x-data-dumper'); + my $req = $t->get(url => + '/serialize/test_second?serialize_content_type=text/x-data-dumper' + ); $req->remove_header('Content-Type'); $req->header('Accept', '*/*'); my $res = request($req); diff --git a/t/lib/Test/Catalyst/Action/REST/Controller/Serialize.pm b/t/lib/Test/Catalyst/Action/REST/Controller/Serialize.pm new file mode 100644 index 0000000..c4111da --- /dev/null +++ b/t/lib/Test/Catalyst/Action/REST/Controller/Serialize.pm @@ -0,0 +1,34 @@ +package Test::Catalyst::Action::REST::Controller::Serialize; + +use strict; +use warnings; +use base 'Catalyst::Controller'; + +__PACKAGE__->config( + 'default' => 'text/x-yaml', + 'stash_key' => 'rest', + 'content_type_stash_key' => 'serialize_content_type', + 'map' => { + 'text/x-yaml' => 'YAML', + 'application/json' => 'JSON', + 'text/x-data-dumper' => [ 'Data::Serializer', 'Data::Dumper' ], + 'text/broken' => 'Broken', + }, +); + +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->{'serialize_content_type'} = $c->req->params->{'serialize_content_type'}; + $c->stash->{'rest'} = { + lou => 'is my cat', + }; +} + +1;