Test uri_with clears query params
Tomas Doran [Tue, 14 Apr 2009 19:25:44 +0000 (19:25 +0000)]
Changes
t/aggregate/live_engine_request_uri.t
t/lib/TestApp/Controller/Engine/Request/URI.pm

diff --git a/Changes b/Changes
index 481b0cb..89af63e 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,8 @@
 # This file documents the revision history for Perl extension Catalyst.
 
+        - Test uri_with clears query params when they are set to undef 
+          (Ian Wells)
+
 5.8000_07 2009-04-12 13:37
         - Add the Catalyst::Dispatcher->dispatch_type method (ash)
         - Throw an exception rather than loading an app if an action
index 4f60c49..b26e156 100644 (file)
@@ -4,7 +4,7 @@ use warnings;
 use FindBin;
 use lib "$FindBin::Bin/../lib";
 
-use Test::More tests => 68;
+use Test::More tests => 74;
 use Catalyst::Test 'TestApp';
 use Catalyst::Request;
 
@@ -79,6 +79,8 @@ SKIP:
     ok( $response->is_success, 'Response Successful 2xx' );
     ok( !defined $response->header( 'X-Catalyst-Param-a' ), 'param "a" ok' );
     is( $response->header( 'X-Catalyst-Param-b' ), '1', 'param "b" ok' );
+    is( $response->header( 'X-Catalyst-Param-c' ), '--notexists--', 'param "c" ok' );
+    unlike($response->header ('X-Catalyst-query'), qr/c=/, 'no c in return');
 }
 
 # test that uri_with adds params (and preserves)
@@ -87,14 +89,18 @@ SKIP:
     ok( $response->is_success, 'Response Successful 2xx' );
     is( $response->header( 'X-Catalyst-Param-a' ), '1', 'param "a" ok' );
     is( $response->header( 'X-Catalyst-Param-b' ), '1', 'param "b" ok' );
+    is( $response->header( 'X-Catalyst-Param-c' ), '--notexists--', 'param "c" ok' );
+    unlike($response->header ('X-Catalyst-query'), qr/c=/, 'no c in return');
 }
 
 # test that uri_with replaces params (and preserves)
 {
-    ok( my $response = request('http://localhost/engine/request/uri/uri_with?a=1&b=2'), 'Request' );
+    ok( my $response = request('http://localhost/engine/request/uri/uri_with?a=1&b=2&c=3'), 'Request' );
     ok( $response->is_success, 'Response Successful 2xx' );
     is( $response->header( 'X-Catalyst-Param-a' ), '1', 'param "a" ok' );
     is( $response->header( 'X-Catalyst-Param-b' ), '1', 'param "b" ok' );
+    is( $response->header( 'X-Catalyst-Param-c' ), '--notexists--', 'param "c" deleted ok' );
+    unlike($response->header ('X-Catalyst-query'), qr/c=/, 'no c in return');
 }
 
 # test that uri_with replaces params (and preserves)
index 2acfd67..3d40780 100644 (file)
@@ -32,11 +32,13 @@ sub uri_with : Local {
     my ( $self, $c ) = @_;
 
     # change the current uri
-    my $uri   = $c->req->uri_with( { b => 1 } );
+    my $uri   = $c->req->uri_with( { b => 1, c => undef } );
     my %query = $uri->query_form;
     
     $c->res->header( 'X-Catalyst-Param-a' => $query{ a } );
     $c->res->header( 'X-Catalyst-Param-b' => $query{ b } );
+    $c->res->header( 'X-Catalyst-Param-c' => exists($query{ c }) ? $query{ c } : '--notexists--' );
+    $c->res->header( 'X-Catalyst-query' => $uri->query);
     
     $c->forward('TestApp::View::Dump::Request');
 }