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