Switch from JSON to JSON::MaybeXS to get a better choice of JSON parsers.
[catagits/Catalyst-Action-REST.git] / t / jsonp.t
1 use strict;
2 use warnings;
3 use Test::More;
4 use FindBin;
5 use Test::Requires qw(JSON::MaybeXS);
6
7 use lib ("$FindBin::Bin/lib", "$FindBin::Bin/../lib");
8 use Test::Rest;
9 use utf8;
10
11 use_ok 'Catalyst::Test', 'Test::Serialize', 'Catalyst::Action::Serialize::JSON';
12
13 my $json = JSON->new->utf8;
14
15 for ('text/javascript','application/x-javascript','application/javascript') {
16     my $t = Test::Rest->new('content_type' => $_);
17     my $monkey_template = { monkey => 'likes chicken!' };
18
19     my $mres = request($t->get(url => '/monkey_get?callback=My_Animal.omnivore'));
20     ok( $mres->is_success, 'GET the monkey succeeded' );
21
22     my ($json_param) = $mres->content =~ /^My_Animal.omnivore\((.*)?\);$/;
23     is_deeply($json->decode($json_param), $monkey_template, "GET returned the right data");
24 }
25
26 1;
27
28 done_testing;