Skip to content

Commit

Permalink
More request tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ambs committed Jun 3, 2011
1 parent d78345b commit 1f787a0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
11 changes: 9 additions & 2 deletions t/02_request/06_init_env.t
Expand Up @@ -5,7 +5,9 @@ use warnings FATAL => 'all';

use Dancer::Request;

my $custom_env = {
my $custom_env = {
'SERVER_PORT' => 3000,
SERVER_PROTOCOL => 'http',
'QUERY_STRING' => 'foo=bar',
'PATH_INFO' => '/stuff',
'REQUEST_METHOD' => 'GET',
Expand All @@ -20,16 +22,21 @@ my $custom_env = {
'HTTP_CONNECTION' => 'keep-alive; keep-alive',
};
my @http_env = grep /^HTTP_/, keys (%$custom_env);
plan tests => 3 + (2 * scalar(@http_env));
plan tests => 6 + (2 * scalar(@http_env));

my $req = Dancer::Request->new($custom_env);
is $req->path, '/stuff', 'path is set from custom env';
is $req->method, 'GET', 'method is set from custom env';
is_deeply scalar($req->params), {foo => 'bar'}, 'params are set from custom env';

is $req->port, 3000, 'port is ok';
is $req->protocol, 'http', 'protocol is ok';
ok !$req->secure, 'not https';

foreach my $http (@http_env) {
my $key = lc $http;
$key =~ s/^http_//;
is $req->{$key}, $custom_env->{$http}, "$http is found in request ($key)";
is $req->$key, $custom_env->{$http}, "$key is an accessor";
}

3 changes: 2 additions & 1 deletion t/02_request/08_params.t
@@ -1,4 +1,4 @@
use Test::More tests => 24;
use Test::More tests => 26;
use strict;
use warnings FATAL => 'all';
use Dancer::Request;
Expand Down Expand Up @@ -34,6 +34,7 @@ use Dancer::Request;
is $req->method, 'GET', 'method is set';
ok $req->is_get, "request method is GET";
is_deeply scalar($req->params), $expected_params, 'params are OK';
is_deeply scalar($req->Vars), $expected_params, 'params are OK (using Vars)';
is $req->params->{'name'}, 'Alexis Sukrieh', 'params accessor works';

my %params = $req->params;
Expand Down

0 comments on commit 1f787a0

Please sign in to comment.