Skip to content

Commit 10f8768

Browse files
committed
Merge branch 'dancer-test-uri' into devel
2 parents 60db699 + 63ac931 commit 10f8768

File tree

3 files changed

+31
-0
lines changed

3 files changed

+31
-0
lines changed

CHANGES

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ Revision history for Dancer
1818
(Yanick Champoux, reported by sciurius)
1919
* GH #954: don't die on autoflush for older perls.
2020
(Yanick Champoux, reported by metateck and David Golden)
21+
* GH #950: Dancer::Test functions now populate REQUEST_URI.
22+
(Yanick Champoux, reported by Sören Kornetzki)
2123

2224
[ DOCUMENTATION ]
2325
* GH #942: simpilify the Apache deployment docs for cgi/fcgi.

lib/Dancer/Test.pm

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,17 @@ sub dancer_response {
361361
$extra_env->{'CONTENT_TYPE'} = $headers->header('Content-Type');
362362
}
363363

364+
# fake the REQUEST_URI
365+
# TODO deal with the params
366+
unless( $extra_env->{REQUEST_URI} ) {
367+
$extra_env->{REQUEST_URI} = $path;
368+
if ( $method eq 'GET' and $params ) {
369+
$extra_env->{REQUEST_URI} .=
370+
'?' . join '&', map { join '=', $_, $params->{$_} }
371+
sort keys %$params;
372+
}
373+
}
374+
364375
my $request = Dancer::Request->new_for_request(
365376
$method => $path,
366377
$params, $body, $headers, $extra_env

t/23_dancer_tests/03_uris.t

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use strict;
2+
use warnings;
3+
4+
use Test::More tests => 5;
5+
6+
use Dancer ':tests';
7+
use Dancer::Test;
8+
9+
get '/uri_base' => sub { request->uri_base };
10+
get '/uri' => sub { request->uri };
11+
get '/path' => sub { request->path };
12+
13+
response_content_is '/uri_base' => 'http://localhost';
14+
response_content_is '/uri' => '/uri';
15+
response_content_is '/uri?with=params' => '/uri?with=params';
16+
response_content_is '/path' => '/path';
17+
response_content_is '/path?with=params' => '/path';
18+

0 commit comments

Comments
 (0)