forked from PerlDancer/Dancer
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test script for Dancer::Serializer->process_request
- Loading branch information
Alexis Sukrieh
committed
Mar 18, 2010
1 parent
891b9a1
commit a188737
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
use strict; | ||
use warnings; | ||
use Test::More; | ||
|
||
plan skip_all => "JSON is needed to run this test" | ||
unless Dancer::ModuleLoader->load('JSON'); | ||
plan tests => 3; | ||
|
||
use Dancer::Config 'setting'; | ||
use Dancer::Request; | ||
use Dancer::Serializer; | ||
use Dancer::Serializer::JSON; | ||
|
||
setting serializer => 'JSON'; | ||
|
||
my $body = '{"foo":42}'; | ||
open my $in, '<', \$body; | ||
|
||
my $env = { | ||
CONTENT_LENGTH => length($body), | ||
CONTENT_TYPE => Dancer::Serializer::JSON->content_type, | ||
REQUEST_METHOD => 'PUT', | ||
SCRIPT_NAME => '/', | ||
'psgi.input' => $in, | ||
}; | ||
|
||
my $expected_params = { | ||
foo => '42', | ||
}; | ||
|
||
my $req = Dancer::Request->new($env); | ||
is $req->body, $body, "body is untouched"; | ||
|
||
my $processed_req = Dancer::Serializer->process_request($req); | ||
is_deeply(scalar($processed_req->params('body')), $expected_params, | ||
"body request has been deserialized"); | ||
is $processed_req->params->{'foo'}, 42, "params have been updated"; |