Add HEAD requests support to T::Rest
[catagits/Catalyst-Action-REST.git] / t / catalyst-controller-rest.t
CommitLineData
0ba73721 1use strict;
2use warnings;
a60f84be 3use Test::More;
0ba73721 4use YAML::Syck;
5use FindBin;
6
7use lib ("$FindBin::Bin/lib", "$FindBin::Bin/../lib", "$FindBin::Bin/broken");
8use Test::Rest;
9
10my $t = Test::Rest->new(content_type => 'text/x-yaml');
11
12use_ok 'Catalyst::Test', 'Test::Catalyst::Action::REST';
13
14my $data = { your => 'face' };
15is_deeply(
16 Load(
17 request($t->put(url => '/rest/test', data => Dump($data)))->content
18 ),
19 { test => 'worked', data => $data },
20 'round trip (deserialize/serialize)',
21);
9fb09119 22
23
24ok my $res = request( $t->get( url => '/rest/test_status_created' ) );
25is $res->code, 201, "... status created";
259c53c7 26is $res->header('Location'), '/rest', "...location of what was created";
9fb09119 27
28ok $res = request( $t->get( url => '/rest/test_status_accepted' ) );
29is $res->code, 202, "... status accepted";
259c53c7 30is $res->header('Location'), '/rest', "...location of what was accepted";
9fb09119 31
32ok $res = request( $t->get( url => '/rest/test_status_no_content' ) );
33is $res->code, 204, "... status no content";
34is $res->content, '', '... no content';
35
e52456a4 36ok $res = request( $t->get( url => '/rest/test_status_found' ) );
37is $res->code, 302, '... status found';
38is_deeply Load( $res->content ),
39 { status => 'found' },
40 "... status found message";
259c53c7 41is $res->header('Location'), '/rest', "...location of what was found";
e52456a4 42
9fb09119 43ok $res = request( $t->get( url => '/rest/test_status_bad_request' ) );
44is $res->code, 400, '... status bad request';
45is_deeply Load( $res->content ),
46 { error => "Cannot do what you have asked!" },
47 "... status bad request message";
48
550807bc 49ok $res = request( $t->get( url => '/rest/test_status_forbidden' ) );
50is $res->code, 403, '... status forbidden';
51is_deeply Load( $res->content ),
52 { error => "access denied" },
53 "... status forbidden";
54
9fb09119 55ok $res = request( $t->get( url => '/rest/test_status_not_found' ) );
56is $res->code, 404, '... status not found';
57is_deeply Load( $res->content ),
58 { error => "Cannot find what you were looking for!" },
59 "... status bad request message";
60
61ok $res = request( $t->get( url => '/rest/test_status_gone' ) );
62is $res->code, 410, '... status gone';
63is_deeply Load( $res->content ),
64 { error => "Document have been deleted by foo" },
65 "... status gone message";
bdff70a9 66
67ok $res = request( $t->get( url => '/rest/test_status_multiple_choices' ) );
68is $res->code, 300, "... multiple choices";
a60f84be 69is_deeply Load($res->content),
70 { choices => [qw(/rest/choice1 /rest/choice2)] },
71 "... 300 multiple choices has response body";
259c53c7 72is $res->header('Location'), '/rest/choice1', "...main location of what was found";
a60f84be 73
74done_testing;
bdff70a9 75