r1682@mbp: claco | 2008-06-16 19:54:33 -0400
[catagits/Catalyst-Action-REST.git] / t / json.t
1 use strict;
2 use warnings;
3 use Test::More tests => 9; 
4 use FindBin;
5
6 use lib ("$FindBin::Bin/lib", "$FindBin::Bin/../lib");
7 use Test::Rest;
8
9 use_ok 'Catalyst::Test', 'Test::Serialize';
10
11 SKIP: {
12     my $has_serializer = eval "require JSON::Syck";
13
14     skip "JSON::Syck not available", 8, unless $has_serializer;
15
16     for ('text/x-json', 'application/json') {
17         my $t = Test::Rest->new('content_type' => $_);
18         my $monkey_template = {
19             monkey => 'likes chicken!',
20         };
21         my $mres = request($t->get(url => '/monkey_get'));
22         ok( $mres->is_success, 'GET the monkey succeeded' );
23         is_deeply(JSON::Syck::Load($mres->content), $monkey_template, "GET returned the right data");
24
25         my $post_data = {
26             'sushi' => 'is good for monkey',
27         };
28         my $mres_post = request($t->post(url => '/monkey_put', data => JSON::Syck::Dump($post_data)));
29         ok( $mres_post->is_success, "POST to the monkey succeeded");
30         is_deeply($mres_post->content, "is good for monkey", "POST data matches");
31     }
32 };
33
34 1;