Lines 34-46
get '/empty' => sub {
Link Here
|
34 |
|
34 |
|
35 |
get '/query' => sub { |
35 |
get '/query' => sub { |
36 |
my $c = shift; |
36 |
my $c = shift; |
37 |
my $input = { |
37 |
my ( $filtered_params, $reserved_params ) = $c->extract_reserved_params($c->req->params->to_hash); |
38 |
_page => 2, |
|
|
39 |
_per_page => 3, |
40 |
firstname => 'Manuel', |
41 |
surname => 'Cohen Arazi' |
42 |
}; |
43 |
my ( $filtered_params, $reserved_params ) = $c->extract_reserved_params($input); |
44 |
$c->render( |
38 |
$c->render( |
45 |
json => { |
39 |
json => { |
46 |
filtered_params => $filtered_params, |
40 |
filtered_params => $filtered_params, |
Lines 50-70
get '/query' => sub {
Link Here
|
50 |
); |
44 |
); |
51 |
}; |
45 |
}; |
52 |
|
46 |
|
53 |
get '/query_full' => sub { |
47 |
get '/query_full/:id/:subid' => sub { |
54 |
my $c = shift; |
48 |
my $c = shift; |
55 |
my $input = { |
49 |
my $params = $c->req->params->to_hash; |
56 |
_match => 'exact', |
50 |
$params->{id} = $c->stash->{id}; |
57 |
_order_by => 'blah', |
51 |
$params->{subid} = $c->stash->{subid}; |
58 |
_page => 2, |
52 |
my ( $filtered_params, $reserved_params, $path_params ) = $c->extract_reserved_params($params); |
59 |
_per_page => 3, |
|
|
60 |
firstname => 'Manuel', |
61 |
surname => 'Cohen Arazi' |
62 |
}; |
63 |
my ( $filtered_params, $reserved_params ) = $c->extract_reserved_params($input); |
64 |
$c->render( |
53 |
$c->render( |
65 |
json => { |
54 |
json => { |
66 |
filtered_params => $filtered_params, |
55 |
filtered_params => $filtered_params, |
67 |
reserved_params => $reserved_params |
56 |
reserved_params => $reserved_params, |
|
|
57 |
path_params => $path_params |
68 |
}, |
58 |
}, |
69 |
status => 200 |
59 |
status => 200 |
70 |
); |
60 |
); |
Lines 187-202
use Test::Mojo;
Link Here
|
187 |
|
177 |
|
188 |
subtest 'extract_reserved_params() tests' => sub { |
178 |
subtest 'extract_reserved_params() tests' => sub { |
189 |
|
179 |
|
190 |
plan tests => 8; |
180 |
plan tests => 9; |
191 |
|
181 |
|
192 |
my $t = Test::Mojo->new; |
182 |
my $t = Test::Mojo->new; |
193 |
|
183 |
|
194 |
$t->get_ok('/query')->status_is(200) |
184 |
$t->get_ok('/query?_page=2&_per_page=3&firstname=Manuel&surname=Cohen%20Arazi')->status_is(200) |
195 |
->json_is( '/filtered_params' => |
185 |
->json_is( '/filtered_params' => |
196 |
{ firstname => 'Manuel', surname => 'Cohen Arazi' } ) |
186 |
{ firstname => 'Manuel', surname => 'Cohen Arazi' } ) |
197 |
->json_is( '/reserved_params' => { _page => 2, _per_page => 3 } ); |
187 |
->json_is( '/reserved_params' => { _page => 2, _per_page => 3 } ); |
198 |
|
188 |
|
199 |
$t->get_ok('/query_full')->status_is(200) |
189 |
$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) |
200 |
->json_is( |
190 |
->json_is( |
201 |
'/filtered_params' => { |
191 |
'/filtered_params' => { |
202 |
firstname => 'Manuel', |
192 |
firstname => 'Manuel', |
Lines 208-213
subtest 'extract_reserved_params() tests' => sub {
Link Here
|
208 |
_per_page => 3, |
198 |
_per_page => 3, |
209 |
_match => 'exact', |
199 |
_match => 'exact', |
210 |
_order_by => 'blah' |
200 |
_order_by => 'blah' |
|
|
201 |
} ) |
202 |
->json_is( |
203 |
'/path_params' => { |
204 |
id => 'with', |
205 |
subid => 'path' |
211 |
} ); |
206 |
} ); |
212 |
|
207 |
|
213 |
}; |
208 |
}; |
214 |
- |
|
|