Permalink
Browse files

Merge branch 'postman-rings-twice'

  • Loading branch information...
2 parents 860471a + 8ef59f5 commit ad7997e200f2093e0606c5d66dc393579efe3972 @yanick yanick committed Mar 11, 2014
Showing with 52 additions and 7 deletions.
  1. +3 −1 Changes
  2. +9 −6 lib/Dancer/Plugin/REST.pm
  3. +40 −0 t/two-posts.t
View
4 Changes
@@ -3,7 +3,9 @@ Revision history for {{$DIST}}
{{$NEXT}}
[BUG FIXES]
- 'prepare_serializer_for_format' was clobbering the default serializer.
- (RT#93478, reported by Pierre Vigier)
+ (RT#93478, reported by Pierre Vigier, fix by Yanick Champoux)
+ - serializer not detected in time for first deserialization.
+ (RT#78437, reported by Andrew Solomon, fix by Yanick Champoux)
0.07 2011-11-01
- Minor updates to fix warnings with Dancer 1.3080
View
15 lib/Dancer/Plugin/REST.pm
@@ -29,12 +29,10 @@ register prepare_serializer_for_format => sub {
);
hook 'before' => sub {
-
- my $format = params->{'format'}
- or return;
-
# remember what was there before
- $default_serializer = setting 'serializer';
+ $default_serializer ||= setting 'serializer';
+
+ my $format = params->{'format'} or return;
my $serializer = $serializers->{$format}
or return halt(
@@ -47,12 +45,17 @@ register prepare_serializer_for_format => sub {
set serializer => $serializer;
+ # check if we were supposed to deserialize the request
+ Dancer::Serializer->process_request(
+ Dancer::SharedData->request
+ );
+
content_type $content_types->{$format} || setting('content_type');
};
hook after => sub {
# put it back the way it was
- set serializer => $default_serializer if $default_serializer;
+ set serializer => $default_serializer;
}
};
View
40 t/two-posts.t
@@ -0,0 +1,40 @@
+use strict;
+use warnings;
+
+{
+ package Foo;
+
+ use Dancer;
+ use Dancer::Plugin::REST;
+
+ prepare_serializer_for_format;
+
+ post '/foo.:format' => sub {
+ return params;
+ };
+
+}
+
+use Test::More;
+use Dancer::ModuleLoader;
+
+plan skip_all => 'tests require JSON'
+ unless Dancer::ModuleLoader->load('JSON');
+
+plan tests => 2;
+
+use Dancer::Test;
+use HTTP::Headers;
+
+my $head = HTTP::Headers->new;
+
+$head->header("content-type" => "application/json");
+
+for ( 1..2 ) {
+ my $resp = dancer_response( 'POST' => '/foo.json', {
+ body => '{"yin":"yang","foo":"bar"}',
+ headers => $head,
+ });
+
+ like $resp->content, qr/yin/;
+}

0 comments on commit ad7997e

Please sign in to comment.