test cases and fixes for the nested param data handler
John Napiorkowski [Wed, 23 Oct 2013 19:57:27 +0000 (14:57 -0500)]
lib/Catalyst.pm
t/data_handler.t
t/lib/TestDataHandlers/Controller/Root.pm

index ae07a90..2e7e837 100644 (file)
@@ -3210,7 +3210,7 @@ sub default_data_handlers {
           my ($fh, $req) = @_;
           my $params = $req->_use_hash_multivalue ? $req->body_parameters->mixed : $req->body_parameters;
           Class::Load::load_first_existing_class('CGI::Struct::XS', 'CGI::Struct')
-            ->('build_cgi_struct')->($params);
+            ->can('build_cgi_struct')->($params);
       },
       'application/json' => sub {
           Class::Load::load_first_existing_class('JSON::MaybeXS', 'JSON')
index 26ce2f9..0d4af33 100644 (file)
@@ -12,13 +12,23 @@ use lib "$FindBin::Bin/lib";
 use Catalyst::Test 'TestDataHandlers';
 
 ok my($res, $c) = ctx_request('/');
-ok my $message = 'helloworld';
-ok my $post = encode_json +{message=>$message};
-ok my $req = POST $c->uri_for_action('/test_json'),
-   Content_Type => 'application/json',
-   Content => $post;
-
-ok my $response = request $req, 'got a response from a catalyst controller';
-is $response->content, $message, 'expected content body';
+
+{
+  ok my $message = 'helloworld';
+  ok my $post = encode_json +{message=>$message};
+  ok my $req = POST $c->uri_for_action('/test_json'),
+     Content_Type => 'application/json',
+     Content => $post;
+
+  ok my $response = request $req, 'got a response from a catalyst controller';
+  is $response->content, $message, 'expected content body';
+}
+
+{
+  ok my $req = POST $c->uri_for_action('/test_nested_for'), [ 'nested.value' => 'expected' ];
+  ok my $response = request $req, 'got a response from a catalyst controller';
+  is $response->content, 'expected', 'expected content body';
+}
+
 
 done_testing;
index 42bf85b..3aa45f4 100644 (file)
@@ -7,4 +7,9 @@ sub test_json :Local {
     $c->res->body($c->req->body_data->{message});
 }
 
+sub test_nested_for :Local {
+    my ($self, $c) = @_;
+    $c->res->body($c->req->body_data->{nested}->{value});
+}
+
 1;