Commit | Line | Data |
e601adda |
1 | package Test::Catalyst::Action::Serialize; |
2 | |
3 | use FindBin; |
4 | |
5 | use lib ("$FindBin::Bin/../lib"); |
6 | |
7 | use strict; |
8 | use warnings; |
9 | |
10 | use Catalyst::Runtime '5.70'; |
11 | |
12 | use 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 | |
29 | sub test :Local :ActionClass('Serialize') { |
30 | my ( $self, $c ) = @_; |
31 | $c->stash->{'rest'} = { |
32 | lou => 'is my cat', |
33 | }; |
34 | } |
35 | |
36 | sub test_second :Local :ActionClass('Serialize') { |
37 | my ( $self, $c ) = @_; |
38 | $c->stash->{'rest'} = { |
39 | lou => 'is my cat', |
40 | }; |
41 | } |
42 | |
43 | package main; |
44 | |
45 | use strict; |
46 | use warnings; |
47 | use Test::More qw(no_plan); |
48 | use Data::Serializer; |
49 | use FindBin; |
50 | use Data::Dump qw(dump); |
51 | |
52 | use lib ("$FindBin::Bin/lib", "$FindBin::Bin/../lib", "$FindBin::Bin/broken"); |
53 | use Test::Rest; |
54 | |
55 | # Should use Data::Dumper, via YAML |
56 | my $t = Test::Rest->new('content_type' => 'text/x-data-dumper'); |
57 | |
58 | use_ok 'Catalyst::Test', 'Test::Catalyst::Action::Serialize'; |
59 | |
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"); |
63 | |
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'); |
67 | |
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'); |
71 | |
72 | # This check is to make sure we can still serialize after the first |
73 | # request. |
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"); |
77 | |
78 | |
79 | 1; |