r55@latte: adam | 2006-12-03 16:09:26 -0800
[catagits/Catalyst-Action-REST.git] / t / catalyst-action-serialize.t
CommitLineData
e601adda 1package Test::Catalyst::Action::Serialize;
2
3use FindBin;
4
5use lib ("$FindBin::Bin/../lib");
6
7use strict;
8use warnings;
9
10use Catalyst::Runtime '5.70';
11
12use Catalyst;
13
14__PACKAGE__->config(
15 name => 'Test::Catalyst::Action::Serialize',
16 serialize => {
17 'default' => 'YAML',
18 'stash_key' => 'rest',
19 'map' => {
20 'text/x-yaml' => 'YAML',
21 'text/x-data-dumper' => [ 'Data::Serializer', 'Data::Dumper' ],
22 'text/broken' => 'Broken',
23 },
24 }
25);
26
27__PACKAGE__->setup;
28
29sub test :Local :ActionClass('Serialize') {
30 my ( $self, $c ) = @_;
31 $c->stash->{'rest'} = {
32 lou => 'is my cat',
33 };
34}
35
36sub test_second :Local :ActionClass('Serialize') {
37 my ( $self, $c ) = @_;
38 $c->stash->{'rest'} = {
39 lou => 'is my cat',
40 };
41}
42
43package main;
44
45use strict;
46use warnings;
6646fdc2 47use Test::More tests => 7;
e601adda 48use Data::Serializer;
49use FindBin;
50use Data::Dump qw(dump);
51
52use lib ("$FindBin::Bin/lib", "$FindBin::Bin/../lib", "$FindBin::Bin/broken");
53use Test::Rest;
54
55# Should use Data::Dumper, via YAML
56my $t = Test::Rest->new('content_type' => 'text/x-data-dumper');
57
58use_ok 'Catalyst::Test', 'Test::Catalyst::Action::Serialize';
59
60my $res = request($t->get(url => '/test'));
61ok( $res->is_success, 'GET the serialized request succeeded' );
62is( $res->content, "{'lou' => 'is my cat'}", "Request returned proper data");
63
64my $nt = Test::Rest->new('content_type' => 'text/broken');
65my $bres = request($nt->get(url => '/test'));
66is( $bres->code, 415, 'GET on un-useable Serialize class returns 415');
67
68my $ut = Test::Rest->new('content_type' => 'text/not-happening');
69my $ures = request($ut->get(url => '/test'));
70is ($bres->code, 415, 'GET on unknown Content-Type returns 415');
71
72# This check is to make sure we can still serialize after the first
73# request.
74my $res2 = request($t->get(url => '/test_second'));
75ok( $res2->is_success, '2nd request succeeded' );
76is( $res2->content, "{'lou' => 'is my cat'}", "2nd request returned proper data");
77
78
791;