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