1 package Test::Catalyst::Action::Serialize;
5 use lib ("$FindBin::Bin/../lib");
10 use Catalyst::Runtime '5.70';
15 name => 'Test::Catalyst::Action::Serialize',
18 'stash_key' => 'rest',
20 'text/x-yaml' => 'YAML',
21 'text/x-data-dumper' => [ 'Data::Serializer', 'Data::Dumper' ],
22 'text/broken' => 'Broken',
29 sub test :Local :ActionClass('Serialize') {
30 my ( $self, $c ) = @_;
31 $c->stash->{'rest'} = {
36 sub test_second :Local :ActionClass('Serialize') {
37 my ( $self, $c ) = @_;
38 $c->stash->{'rest'} = {
47 use Test::More tests => 7;
50 use Data::Dump qw(dump);
52 use lib ("$FindBin::Bin/lib", "$FindBin::Bin/../lib", "$FindBin::Bin/broken");
55 # Should use Data::Dumper, via YAML
56 my $t = Test::Rest->new('content_type' => 'text/x-data-dumper');
58 use_ok 'Catalyst::Test', 'Test::Catalyst::Action::Serialize';
60 my $res = request($t->get(url => '/test'));
61 ok( $res->is_success, 'GET the serialized request succeeded' );
62 is( $res->content, "{'lou' => 'is my cat'}", "Request returned proper data");
64 my $nt = Test::Rest->new('content_type' => 'text/broken');
65 my $bres = request($nt->get(url => '/test'));
66 is( $bres->code, 415, 'GET on un-useable Serialize class returns 415');
68 my $ut = Test::Rest->new('content_type' => 'text/not-happening');
69 my $ures = request($ut->get(url => '/test'));
70 is ($bres->code, 415, 'GET on unknown Content-Type returns 415');
72 # This check is to make sure we can still serialize after the first
74 my $res2 = request($t->get(url => '/test_second'));
75 ok( $res2->is_success, '2nd request succeeded' );
76 is( $res2->content, "{'lou' => 'is my cat'}", "2nd request returned proper data");