Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

resource params (:id, :format, etc) not properly set #3

Merged
merged 1 commit into from

2 participants

@garu
Collaborator

Hi there!

It looks like the code refactoring on commit 2f64ae1 broke some bits of Dancer::Plugin::REST. In particular, it does not separate the ":format" from the rest of the parameter anymore. Up until the previous commit (d1f74b6), if you had something like:

resource user => get => sub { my $id = params->{id}; my $format = params->{format} };

and you issued a GET '/user/42.json', you'd get $id as '42' and $format as 'json'. On commit 2f64ae1 onwards this does not happen anymore. Instead, you get $id as '42.json' and $format as undef. Since this is not the expected outcome (from both the docs and all the previous versions), I wrote a test case for this, which this commit is all about.

The test passes on d1f74b6 but explodes on 2f64ae1 onwards. I haven't really looked into a fix on Dancer::Plugin::REST itself (I was debugging this on my own API), but I figured the test should give you guys a good head start.

Cheers!

@garu garu changed the title from tests for resource params and prepare_serializer_for_format to resource params (:id, :format, etc) not properly set
@yanick yanick referenced this pull request from a commit
@yanick yanick order of route creation is important
Fixes #3
6755186
@yanick yanick merged commit 2351618 into PerlDancer:master
@yanick
Owner

Do'h! Mistake corrected and new release pushed. Thanks!

@garu garu deleted the garu:master branch
@garu
Collaborator

Thanks!

@yanick
Owner

No, no, no: thank you. That test file was super-useful. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 25, 2014
  1. @garu
This page is out of date. Refresh to see the latest.
Showing with 49 additions and 0 deletions.
  1. +49 −0 t/05_serializer_and_resource.t
View
49 t/05_serializer_and_resource.t
@@ -0,0 +1,49 @@
+use strict;
+use warnings;
+use Dancer::ModuleLoader;
+use Test::More import => ['!pass'];
+
+# Dancer::Test had a bug in version previous 1.3059_01 that prevent this test
+# from running correctly.
+my $dancer_version = eval "\$Dancer::VERSION";
+$dancer_version =~ s/_//g;
+plan skip_all => "Dancer 1.3059_01 is needed for this test (you have $dancer_version)"
+ if $dancer_version < 1.305901;
+
+{
+ package Webservice;
+ use Dancer;
+ use Dancer::Plugin::REST;
+
+ setting environment => 'testing';
+ prepare_serializer_for_format;
+ resource user =>
+ get => sub { [ id => params->{id}, format => params->{format} ] },
+ delete => sub { [ id => params->{id}, format => params->{format} ] },
+ create => sub { [ user => params->{user}, format => params->{format} ] },
+ update => sub { [ user => params->{user}, format => params->{format} ] };
+}
+
+use Dancer::Test;
+plan tests => 4;
+
+my $r = dancer_response GET => '/user/42.json';
+
+is $r->{content}, '["id","42","format","json"]'
+ => "'id' and 'format' params are properly set for resource during GET";
+
+$r = dancer_response POST => '/user.json', { params => { user => 'test' } };
+
+is $r->{content}, '["user","test","format","json"]'
+ => "'user' and 'format' params properly set for resource during POST";
+
+$r = dancer_response PUT => '/user/1.json', { params => { user => 'anothertest' } };
+
+is $r->{content}, '["user","anothertest","format","json"]'
+ => "'user' and 'format' params properly set for resource during PUT";
+
+$r = dancer_response DELETE => '/user/6.json';
+
+is $r->{content}, '["id","6","format","json"]'
+ => "'id' and 'format' params properly set for resource during DELETE";
+
Something went wrong with that request. Please try again.