Commit | Line | Data |
7ad87df9 |
1 | use strict; |
2 | use warnings; |
3 | use Test::More qw(no_plan); |
4 | use YAML::Syck; |
5 | use FindBin; |
6 | |
7 | use lib ("$FindBin::Bin/lib", "$FindBin::Bin/../lib"); |
8 | use Test::Rest; |
9 | |
10 | # Should use the default serializer, YAML |
11 | my $t = Test::Rest->new('content_type' => 'text/plain'); |
12 | |
13 | BEGIN { use_ok 'Catalyst::Test', 'SampleREST' } |
14 | |
15 | my $mres = request($t->get(url => '/monkey')); |
16 | # We should find the monkey |
17 | ok( $mres->is_success, 'GET the monkey succeeded' ); |
18 | |
19 | # We should use the default serializer, YAML |
20 | my $monkey_template = { |
21 | monkey => 'likes chicken!', |
22 | }; |
23 | my $monkey_data = Load($mres->content); |
24 | is_deeply($monkey_data, $monkey_template, "GET returned the right data"); |
25 | |
26 | $t->{'content_type'} = 'text/x-yaml'; # Try again, with x-yaml |
27 | my $mres_yaml = request($t->get(url => '/monkey')); |
28 | ok( $mres_yaml->is_success, 'GET the monkey x-yaml succeeded' ); |
29 | is_deeply(Load($mres_yaml->content), $monkey_template, "GET x-yaml returned the right data"); |
30 | |
31 | $t->{'content_type'} = 'text/plain'; # Try again, with text/plain |
32 | my $post_data = { |
33 | 'sushi' => 'is good for monkey', |
34 | }; |
35 | my $mres_post = request($t->post(url => '/monkey', data => Dump($post_data))); |
36 | ok( $mres_post->is_success, "POST to the monkey succeeded"); |
37 | is_deeply($mres_post->content, Dump($post_data), "POST data matches"); |
38 | |
39 | my $mdel = request($t->delete(url => '/monkey')); |
40 | ok(! $mdel->is_success, "DELETE-ing the monkey failed; long live monkey!"); |
41 | ok($mdel->code eq "405", "DELETE-ing the monkey returned 405"); |
42 | my @allowed = $mdel->header('allow'); |
43 | my @rallowed = qw(GET POST); |
44 | ok(@allowed eq @rallowed, "Default 405 handler returned proper methods in Allow header"); |
45 | |
46 | 1; |