Skip to content
This repository has been archived by the owner on Jan 22, 2019. It is now read-only.

Support for method PATCH #13

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/Net/HTTP/Spore/Meta/Method.pm
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ subtype UriPath
=> where { $_ =~ m!^/! }
=> message {"path must start with /"};

enum Method => qw(OPTIONS HEAD GET POST PUT DELETE TRACE);
enum Method => qw(OPTIONS HEAD GET POST PUT DELETE TRACE PATCH);

subtype 'JSON::XS::Boolean' => as 'JSON::XS::Boolean';
subtype 'JSON::PP::Boolean' => as 'JSON::PP::Boolean';
Expand Down Expand Up @@ -144,10 +144,10 @@ sub wrap {
: delete $method_args{payload};

if ( $payload
&& ( $method->method !~ /^P(?:OS|U)T$/i ) )
&& ( $method->method !~ /^(?:POST|PUT|PATCH)$/i ) )
{
die Net::HTTP::Spore::Response->new( 599, [],
{ error => "payload requires a PUT or POST method" },
{ error => "payload requires a PUT, PATCH or POST method" },
);
}

Expand Down
12 changes: 10 additions & 2 deletions t/spore-method/payload.t
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use strict;
use warnings;
use Test::More tests => 4;
use Test::More tests => 6;

use Test::Exception;

Expand All @@ -15,6 +15,11 @@ my $api_with_payload = {
path => '/user',
required_payload => 1,
},
update_user => {
method => 'PATCH',
path => '/user',
required_payload => 1,
},
list_user => {
method => 'GET',
path => '/user',
Expand All @@ -30,4 +35,7 @@ dies_ok { $obj->create_user(); };
like $@->body->{error}, qr/this method require a payload/;

dies_ok { $obj->list_user( payload => {} ) };
like $@->body->{error}, qr/payload requires a PUT or POST method/;
like $@->body->{error}, qr/payload requires a PUT, PATCH or POST method/;

dies_ok { $obj->update_user(); };
like $@->body->{error}, qr/this method require a payload/;