v1.21
[catagits/Catalyst-Action-REST.git] / t / lib / Test / Catalyst / Action / REST / Controller / REST.pm
1 package Test::Catalyst::Action::REST::Controller::REST;
2
3 use Moose;
4 use namespace::autoclean;
5
6 BEGIN { extends 'Catalyst::Controller::REST' }
7
8 __PACKAGE__->config(
9   'map' => {
10     'text/html'          => 'YAML::HTML',
11     'text/x-yaml'        => 'YAML',
12 });
13
14 sub test : Local {
15     my ( $self, $c ) = @_;
16     $self->status_ok( $c,
17         entity => { test => 'worked', data => $c->req->data } );
18 }
19
20 sub test_status_created : Local {
21     my ( $self, $c ) = @_;
22     $self->status_created(
23         $c,
24         location => '/rest',
25         entity   => { status => 'created' }
26     );
27 }
28
29 sub test_status_multiple_choices : Local {
30     my ( $self, $c ) = @_;
31     $self->status_multiple_choices(
32         $c,
33         location => '/rest/choice1',
34         entity   => { choices => [qw(/rest/choice1 /rest/choice2)] }
35     );
36 }
37
38 sub test_status_found : Local {
39     my ( $self, $c ) = @_;
40     $self->status_found(
41         $c,
42         location => '/rest',
43         entity   => { status => 'found' },
44     );
45 }
46
47 sub test_status_accepted : Local {
48     my ( $self, $c ) = @_;
49     $self->status_accepted(
50         $c,
51         location => '/rest',
52         entity => { status => "queued", }
53     );
54 }
55
56 sub test_status_no_content : Local {
57     my ( $self, $c ) = @_;
58     $self->status_no_content($c);
59 }
60
61 sub test_status_bad_request : Local {
62     my ( $self, $c ) = @_;
63     $self->status_bad_request( $c,
64         message => "Cannot do what you have asked!", );
65 }
66
67 sub test_status_forbidden : Local {
68     my ( $self, $c ) = @_;
69     $self->status_forbidden ( $c,
70         message => "access denied", );
71 }
72
73 sub test_status_not_found : Local {
74     my ( $self, $c ) = @_;
75     $self->status_not_found( $c,
76         message => "Cannot find what you were looking for!", );
77 }
78
79 sub test_status_gone : Local {
80     my ( $self, $c ) = @_;
81     $self->status_gone( $c,
82         message => "Document have been deleted by foo", );
83 }
84
85 sub test_status_see_other : Local {
86     my ( $self, $c ) = @_;
87     $self->status_see_other(
88         $c,
89         location => '/rest',
90         entity   => { somethin => 'happenin' }
91     );
92 }
93
94 sub opts : Local ActionClass('REST') {}
95
96 sub opts_GET {
97     my ( $self, $c ) = @_;
98     $self->status_ok( $c, entity => { opts => 'worked' } );
99 }
100
101 sub opts_not_implemented {
102     my ( $self, $c ) = @_;
103     $c->res->status(405);
104     $c->res->header('Allow' => [qw(GET HEAD)]);
105     $c->res->body('Not implemented');
106 }
107
108 1;