Split into new dist
[catagits/Catalyst-Action-Serialize-Data-Serializer.git] / t / lib / Test / Catalyst / Action / REST / Controller / Serialize.pm
1 package Test::Catalyst::Action::REST::Controller::Serialize;
2
3 use Moose;
4 use namespace::autoclean;
5
6 BEGIN { extends 'Catalyst::Controller' }
7
8 __PACKAGE__->config(
9     'default'   => 'text/x-yaml',
10     'stash_key' => 'rest',
11     'map'       => {
12         'text/x-data-dumper' => [ 'Data::Serializer', 'Data::Dumper' ],
13     },
14 );
15
16 sub test :Local :ActionClass('Serialize') {
17     my ( $self, $c ) = @_;
18     $c->stash->{'rest'} = {
19         lou => 'is my cat',
20     };
21 }
22
23 sub test_second :Local :ActionClass('Serialize') {
24     my ( $self, $c ) = @_;
25     # 'serialize_content_type' is configured in the test config in t/conf
26     $c->stash->{'serialize_content_type'} = $c->req->params->{'serialize_content_type'};
27     $c->stash->{'rest'} = {
28         lou => 'is my cat',
29     };
30 }
31
32 # For testing saying 'here is an explicitly empty body, do not serialize'
33 sub empty : Chained('/') PathPart('serialize') CaptureArgs(0) {
34     my ($self, $c) = @_;
35     $c->stash( rest => { foo => 'bar' } );
36 }
37
38 # Normal case
39 sub empty_serialized :Chained('empty') Args(0) ActionClass('Serialize') {
40 }
41
42 # Blank body
43 sub empty_not_serialized_blank :Chained('empty') Args(0) ActionClass('Serialize') {
44     my ($self, $c) = @_;
45     $c->res->body('');
46 }
47
48 # Explicitly set a view
49 sub explicit_view :Chained('empty') Args(0) ActionClass('Serialize') {
50     my ($self, $c) = @_;
51     $c->stash->{current_view} = '';
52 }
53
54 1;