From: jshirley Date: Wed, 20 Aug 2008 17:44:12 +0000 (+0000) Subject: Fixing the tests to run without JSON at all, revamping the author/contrib section X-Git-Tag: 0.67_01~22 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2f7533ed98d3c3821696968844cbe4ff12159490;hp=9c5c9bd17536880f866fea9967bc460c674f0b2d;p=catagits%2FCatalyst-Action-REST.git Fixing the tests to run without JSON at all, revamping the author/contrib section --- diff --git a/Changes b/Changes index 11c4c76..064dfa2 100644 --- a/Changes +++ b/Changes @@ -1,3 +1,8 @@ +Wed Aug 20 10:42:00 PST 2008 (jshirley) - Release 0.65 + Fully revamped tests to work without any JSON support + Final removal of JSON::Syck + Special thanks to jgoulah for helping test this release + Wed Aug 13 08:55:00 PST 2008 (jshirley) - Release 0.64 New dist to fix issue with Module::Install diff --git a/Makefile.PL b/Makefile.PL index f5609ce..db75295 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -17,8 +17,8 @@ requires('Data::Dump' => undef); feature 'JSON (application/json) support', -default => 0, - 'JSON' => undef; - 'JSON::XS' => undef; + 'JSON' => '2.12'; + 'JSON::XS' => '2.2222'; feature 'Data::Denter (text/x-data-denter) support', -default => 0, diff --git a/lib/Catalyst/Action/REST.pm b/lib/Catalyst/Action/REST.pm index cdeb8f1..f4105aa 100644 --- a/lib/Catalyst/Action/REST.pm +++ b/lib/Catalyst/Action/REST.pm @@ -18,7 +18,7 @@ use Catalyst::Controller::REST; BEGIN { require 5.008001; } -our $VERSION = '0.64'; +our $VERSION = '0.65'; # This is wrong in several ways. First, there's no guarantee that # Catalyst.pm has not been subclassed. Two, there's no guarantee that @@ -155,16 +155,26 @@ a sensible set of defaults for a controller doing REST. L, L -=head1 AUTHOR +=head1 MAINTAINER -Adam Jacob , with lots of help from mst and jrockway +J. Shirley -Marchex, Inc. paid me while I developed this module. (http://www.marchex.com) +=head1 CONTRIBUTORS -=head1 CONTRIBUTERS +Christopher Laco + +Luke Saunders + +John Goulah Daisuke Maki +=head1 AUTHOR + +Adam Jacob , with lots of help from mst and jrockway + +Marchex, Inc. paid me while I developed this module. (http://www.marchex.com) + =head1 LICENSE You may distribute this code under the same terms as Perl itself. diff --git a/lib/Catalyst/Controller/REST.pm b/lib/Catalyst/Controller/REST.pm index 9608495..9ad724a 100644 --- a/lib/Catalyst/Controller/REST.pm +++ b/lib/Catalyst/Controller/REST.pm @@ -1,6 +1,6 @@ package Catalyst::Controller::REST; -our $VERSION = 0.64; +our $VERSION = '0.65'; =head1 NAME diff --git a/t/catalyst-action-serialize-accept.t b/t/catalyst-action-serialize-accept.t index 12f5df6..13dead9 100644 --- a/t/catalyst-action-serialize-accept.t +++ b/t/catalyst-action-serialize-accept.t @@ -18,7 +18,7 @@ __PACKAGE__->config( 'stash_key' => 'rest', 'map' => { 'text/x-yaml' => 'YAML', - 'application/json' => 'JSON', + 'application/json' => 'JSON', 'text/x-data-dumper' => [ 'Data::Serializer', 'Data::Dumper' ], 'text/broken' => 'Broken', }, @@ -49,7 +49,6 @@ use Test::More tests => 10; use Data::Serializer; use FindBin; use Data::Dump qw(dump); -use JSON::Syck; use lib ("$FindBin::Bin/lib", "$FindBin::Bin/../lib", "$FindBin::Bin/broken"); use Test::Rest; @@ -69,21 +68,32 @@ EOH $req->remove_header('Content-Type'); $req->header('Accept', 'text/x-yaml'); my $res = request($req); - ok( $res->is_success, 'GET the serialized request succeeded' ); - is( $res->content, $data, "Request returned proper data"); - is( $res->header('Content-type'), 'text/x-yaml', '... with expected content-type') + SKIP: { + skip "can't test text/x-yaml without YAML support", + 3 if ( + not $res->is_success and + $res->content =~ m#Content-Type text/x-yaml is not supported# + ); + ok( $res->is_success, 'GET the serialized request succeeded' ); + is( $res->content, $data, "Request returned proper data"); + is( $res->header('Content-type'), 'text/x-yaml', '... with expected content-type') + + }; } -{ - my $at = Test::Rest->new('content_type' => 'text/doesnt-exist'); +SKIP: { + eval 'require JSON'; + skip "can't test application/json without JSON support", 3 if $@; + my $json = JSON->new; + my $at = Test::Rest->new('content_type' => 'text/doesnt-exist'); my $req = $at->get(url => '/test'); $req->header('Accept', 'application/json'); my $res = request($req); - ok( $res->is_success, 'GET the serialized request succeeded' ); - my $ret = JSON::Syck::Load($res->content); - is( $ret->{lou}, 'is my cat', "Request returned proper data"); - is( $res->header('Content-type'), 'application/json', 'Accept header used if content-type mapping not found') -} + ok( $res->is_success, 'GET the serialized request succeeded' ); + my $ret = $json->decode($res->content); + is( $ret->{lou}, 'is my cat', "Request returned proper data"); + is( $res->header('Content-type'), 'application/json', 'Accept header used if content-type mapping not found') +}; # Make sure we don't get a bogus content-type when using default # serializer (rt.cpan.org ticket 27949) diff --git a/t/catalyst-request-rest.t b/t/catalyst-request-rest.t index 4493897..98b3517 100644 --- a/t/catalyst-request-rest.t +++ b/t/catalyst-request-rest.t @@ -87,7 +87,7 @@ use HTTP::Headers; $request->headers( HTTP::Headers->new ); $request->parameters( {} ); $request->method('GET'); - $request->content_type('text/x-json'); + $request->content_type('application/json'); $request->headers->header( 'Accept' => # From Firefox 2.0 when it requests an html page @@ -95,7 +95,7 @@ use HTTP::Headers; ); is_deeply( $request->accepted_content_types, - [ qw( text/x-json + [ qw( application/json text/xml application/xml application/xhtml+xml image/png text/html diff --git a/t/json.t b/t/json.t index 8b05bc4..e3a13da 100644 --- a/t/json.t +++ b/t/json.t @@ -1,34 +1,35 @@ use strict; use warnings; -use Test::More tests => 9; +use Test::More; use FindBin; use lib ("$FindBin::Bin/lib", "$FindBin::Bin/../lib"); use Test::Rest; -use_ok 'Catalyst::Test', 'Test::Serialize'; +eval 'require JSON'; +plan skip_all => 'Install JSON to run this test' if ($@); -SKIP: { - my $has_serializer = eval "require JSON::Syck"; +plan tests => 9; - skip "JSON::Syck not available", 8, unless $has_serializer; +use_ok 'Catalyst::Test', 'Test::Serialize'; - for ('text/x-json', 'application/json') { - my $t = Test::Rest->new('content_type' => $_); - my $monkey_template = { - monkey => 'likes chicken!', - }; - my $mres = request($t->get(url => '/monkey_get')); - ok( $mres->is_success, 'GET the monkey succeeded' ); - is_deeply(JSON::Syck::Load($mres->content), $monkey_template, "GET returned the right data"); +my $json = JSON->new; +# The text/x-json should throw a warning +for ('text/x-json', 'application/json') { + my $t = Test::Rest->new('content_type' => $_); + my $monkey_template = { + monkey => 'likes chicken!', + }; + my $mres = request($t->get(url => '/monkey_get')); + ok( $mres->is_success, 'GET the monkey succeeded' ); + is_deeply($json->decode($mres->content), $monkey_template, "GET returned the right data"); - my $post_data = { - 'sushi' => 'is good for monkey', - }; - my $mres_post = request($t->post(url => '/monkey_put', data => JSON::Syck::Dump($post_data))); - ok( $mres_post->is_success, "POST to the monkey succeeded"); - is_deeply($mres_post->content, "is good for monkey", "POST data matches"); - } -}; + my $post_data = { + 'sushi' => 'is good for monkey', + }; + my $mres_post = request($t->post(url => '/monkey_put', data => $json->encode($post_data))); + ok( $mres_post->is_success, "POST to the monkey succeeded"); + is_deeply($mres_post->content, "is good for monkey", "POST data matches"); +} 1;