Skip to content

Commit

Permalink
some tests for GH#106
Browse files Browse the repository at this point in the history
  • Loading branch information
fcuny authored and Alexis Sukrieh committed Sep 24, 2010
1 parent 0bcd338 commit f65526a
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 2 deletions.
63 changes: 63 additions & 0 deletions t/14_serializer/12_bug_gh106.t
@@ -0,0 +1,63 @@
use strict;
use warnings;
use Test::More import => ['!pass'];

BEGIN {
use Dancer::ModuleLoader;

plan skip_all => "LWP::UserAgent is needed to run this tests"
unless Dancer::ModuleLoader->load('LWP::UserAgent');
plan skip_all => 'Test::TCP is needed to run this test'
unless Dancer::ModuleLoader->load('Test::TCP');
plan skip_all => 'JSON is needed to run this test'
unless Dancer::ModuleLoader->load('JSON');
plan skip_all => 'HTTP::Request is needed to run this test'
unless Dancer::ModuleLoader->load('HTTP::Request');
}

plan tests => 6;

use Dancer;

Test::TCP::test_tcp(
client => sub {
my $port = shift;
my $url = "http://127.0.0.1:$port/";
my $req = HTTP::Request->new( GET => $url );
$req->header( 'Content-Type' => 'application/json' );
my $ua = LWP::UserAgent->new;
ok my $res = $ua->request($req);
is $res->code, 200;
is_deeply(JSON::decode_json($res->content), {foo => 1});
},
server => sub {
my $port = shift;
load_app 't::lib::TestSerializer';
setting access_log => 0;
setting port => $port;
Dancer->dance();
}
);

Test::TCP::test_tcp(
client => sub {
my $port = shift;
my $url = "http://127.0.0.1:$port/blessed";
my $req = HTTP::Request->new( GET => $url );
$req->header( 'Content-Type' => 'application/json' );
my $ua = LWP::UserAgent->new;
ok my $res = $ua->request($req);
is $res->code, 200;
is_deeply( JSON::decode_json( $res->content ), { request => undef } );
},
server => sub {
my $port = shift;
load_app 't::lib::TestSerializer';
setting access_log => 0;
setting port => $port;
setting engines =>
{ JSON => { allow_blessed => 1, convert_blessed => 1 } };
Dancer->dance();
}
);

10 changes: 8 additions & 2 deletions t/lib/TestSerializer.pm
Expand Up @@ -2,14 +2,20 @@ package t::lib::TestSerializer;

use Dancer;

set serializer => 'JSON';
setting serializer => 'JSON';

get '/' => sub {
{ foo => 1 }
};

get '/blessed' => sub {
require HTTP::Headers;
my $r = HTTP::Request->new(GET => 'http://localhost');
{request => $r};
};

post '/' => sub {
request->params;
request->params;
};

get '/error' => sub {
Expand Down

0 comments on commit f65526a

Please sign in to comment.