Lines 35-47
get '/empty' => sub {
Link Here
|
35 |
|
35 |
|
36 |
get '/query' => sub { |
36 |
get '/query' => sub { |
37 |
my $c = shift; |
37 |
my $c = shift; |
38 |
my $input = { |
38 |
my ( $filtered_params, $reserved_params ) = $c->extract_reserved_params($c->req->params->to_hash); |
39 |
_page => 2, |
|
|
40 |
_per_page => 3, |
41 |
firstname => 'Manuel', |
42 |
surname => 'Cohen Arazi' |
43 |
}; |
44 |
my ( $filtered_params, $reserved_params ) = $c->extract_reserved_params($input); |
45 |
$c->render( |
39 |
$c->render( |
46 |
json => { |
40 |
json => { |
47 |
filtered_params => $filtered_params, |
41 |
filtered_params => $filtered_params, |
Lines 51-71
get '/query' => sub {
Link Here
|
51 |
); |
45 |
); |
52 |
}; |
46 |
}; |
53 |
|
47 |
|
54 |
get '/query_full' => sub { |
48 |
get '/query_full/:id/:subid' => sub { |
55 |
my $c = shift; |
49 |
my $c = shift; |
56 |
my $input = { |
50 |
my $params = $c->req->params->to_hash; |
57 |
_match => 'exact', |
51 |
$params->{id} = $c->stash->{id}; |
58 |
_order_by => 'blah', |
52 |
$params->{subid} = $c->stash->{subid}; |
59 |
_page => 2, |
53 |
my ( $filtered_params, $reserved_params, $path_params ) = $c->extract_reserved_params($params); |
60 |
_per_page => 3, |
|
|
61 |
firstname => 'Manuel', |
62 |
surname => 'Cohen Arazi' |
63 |
}; |
64 |
my ( $filtered_params, $reserved_params ) = $c->extract_reserved_params($input); |
65 |
$c->render( |
54 |
$c->render( |
66 |
json => { |
55 |
json => { |
67 |
filtered_params => $filtered_params, |
56 |
filtered_params => $filtered_params, |
68 |
reserved_params => $reserved_params |
57 |
reserved_params => $reserved_params, |
|
|
58 |
path_params => $path_params |
69 |
}, |
59 |
}, |
70 |
status => 200 |
60 |
status => 200 |
71 |
); |
61 |
); |
Lines 202-217
use Test::Mojo;
Link Here
|
202 |
|
192 |
|
203 |
subtest 'extract_reserved_params() tests' => sub { |
193 |
subtest 'extract_reserved_params() tests' => sub { |
204 |
|
194 |
|
205 |
plan tests => 8; |
195 |
plan tests => 9; |
206 |
|
196 |
|
207 |
my $t = Test::Mojo->new; |
197 |
my $t = Test::Mojo->new; |
208 |
|
198 |
|
209 |
$t->get_ok('/query')->status_is(200) |
199 |
$t->get_ok('/query?_page=2&_per_page=3&firstname=Manuel&surname=Cohen%20Arazi')->status_is(200) |
210 |
->json_is( '/filtered_params' => |
200 |
->json_is( '/filtered_params' => |
211 |
{ firstname => 'Manuel', surname => 'Cohen Arazi' } ) |
201 |
{ firstname => 'Manuel', surname => 'Cohen Arazi' } ) |
212 |
->json_is( '/reserved_params' => { _page => 2, _per_page => 3 } ); |
202 |
->json_is( '/reserved_params' => { _page => 2, _per_page => 3 } ); |
213 |
|
203 |
|
214 |
$t->get_ok('/query_full')->status_is(200) |
204 |
$t->get_ok('/query_full/with/path?_match=exact&_order_by=blah&_page=2&_per_page=3&firstname=Manuel&surname=Cohen%20Arazi')->status_is(200) |
215 |
->json_is( |
205 |
->json_is( |
216 |
'/filtered_params' => { |
206 |
'/filtered_params' => { |
217 |
firstname => 'Manuel', |
207 |
firstname => 'Manuel', |
Lines 223-228
subtest 'extract_reserved_params() tests' => sub {
Link Here
|
223 |
_per_page => 3, |
213 |
_per_page => 3, |
224 |
_match => 'exact', |
214 |
_match => 'exact', |
225 |
_order_by => 'blah' |
215 |
_order_by => 'blah' |
|
|
216 |
} ) |
217 |
->json_is( |
218 |
'/path_params' => { |
219 |
id => 'with', |
220 |
subid => 'path' |
226 |
} ); |
221 |
} ); |
227 |
|
222 |
|
228 |
}; |
223 |
}; |
229 |
- |
|
|