Skip to content

Commit

Permalink
Merge branch 'dancer-test-uri' into devel
Browse files Browse the repository at this point in the history
  • Loading branch information
yanick committed Aug 27, 2013
2 parents 60db699 + 63ac931 commit 10f8768
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Expand Up @@ -18,6 +18,8 @@ Revision history for Dancer
(Yanick Champoux, reported by sciurius)
* GH #954: don't die on autoflush for older perls.
(Yanick Champoux, reported by metateck and David Golden)
* GH #950: Dancer::Test functions now populate REQUEST_URI.
(Yanick Champoux, reported by Sören Kornetzki)

[ DOCUMENTATION ]
* GH #942: simpilify the Apache deployment docs for cgi/fcgi.
Expand Down
11 changes: 11 additions & 0 deletions lib/Dancer/Test.pm
Expand Up @@ -361,6 +361,17 @@ sub dancer_response {
$extra_env->{'CONTENT_TYPE'} = $headers->header('Content-Type');
}

# fake the REQUEST_URI
# TODO deal with the params
unless( $extra_env->{REQUEST_URI} ) {
$extra_env->{REQUEST_URI} = $path;
if ( $method eq 'GET' and $params ) {
$extra_env->{REQUEST_URI} .=
'?' . join '&', map { join '=', $_, $params->{$_} }
sort keys %$params;
}
}

my $request = Dancer::Request->new_for_request(
$method => $path,
$params, $body, $headers, $extra_env
Expand Down
18 changes: 18 additions & 0 deletions t/23_dancer_tests/03_uris.t
@@ -0,0 +1,18 @@
use strict;
use warnings;

use Test::More tests => 5;

use Dancer ':tests';
use Dancer::Test;

get '/uri_base' => sub { request->uri_base };
get '/uri' => sub { request->uri };
get '/path' => sub { request->path };

response_content_is '/uri_base' => 'http://localhost';
response_content_is '/uri' => '/uri';
response_content_is '/uri?with=params' => '/uri?with=params';
response_content_is '/path' => '/path';
response_content_is '/path?with=params' => '/path';

0 comments on commit 10f8768

Please sign in to comment.