r49@latte: adam | 2006-12-03 12:30:40 -0800
[catagits/Catalyst-Action-REST.git] / t / 02-json.t
1 use strict;
2 use warnings;
3 use Test::More qw(no_plan);
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 my $t = Test::Rest->new('content_type' => 'text/x-json');
12
13 my $has_serializer = eval "require JSON::Syck";
14 SKIP: {
15     skip "JSON::Syck not available", 4, unless $has_serializer;
16
17     my $monkey_template = {
18         monkey => 'likes chicken!',
19     };
20     my $mres = request($t->get(url => '/monkey_get'));
21     ok( $mres->is_success, 'GET the monkey succeeded' );
22     is_deeply(JSON::Syck::Load($mres->content), $monkey_template, "GET returned the right data");
23
24     my $post_data = {
25         'sushi' => 'is good for monkey',
26     };
27     my $mres_post = request($t->post(url => '/monkey_put', data => JSON::Syck::Dump($post_data)));
28     ok( $mres_post->is_success, "POST to the monkey succeeded");
29     is_deeply($mres_post->content, "is good for monkey", "POST data matches");
30 };
31
32 1;