From: John Napiorkowski Date: Wed, 23 Oct 2013 19:57:27 +0000 (-0500) Subject: test cases and fixes for the nested param data handler X-Git-Tag: 5.90050~1^2~10 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=commitdiff_plain;h=3eba0dd58db00c12f2847f38e479677bb582e4d7;hp=2d802c4a34d83aedcad4fb7686f9f54f24a1fcef test cases and fixes for the nested param data handler --- diff --git a/lib/Catalyst.pm b/lib/Catalyst.pm index ae07a90..2e7e837 100644 --- a/lib/Catalyst.pm +++ b/lib/Catalyst.pm @@ -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') diff --git a/t/data_handler.t b/t/data_handler.t index 26ce2f9..0d4af33 100644 --- a/t/data_handler.t +++ b/t/data_handler.t @@ -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; diff --git a/t/lib/TestDataHandlers/Controller/Root.pm b/t/lib/TestDataHandlers/Controller/Root.pm index 42bf85b..3aa45f4 100644 --- a/t/lib/TestDataHandlers/Controller/Root.pm +++ b/t/lib/TestDataHandlers/Controller/Root.pm @@ -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;