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 136-151
use Test::Mojo;
Link Here
|
136 |
|
126 |
|
137 |
subtest 'extract_reserved_params() tests' => sub { |
127 |
subtest 'extract_reserved_params() tests' => sub { |
138 |
|
128 |
|
139 |
plan tests => 8; |
129 |
plan tests => 9; |
140 |
|
130 |
|
141 |
my $t = Test::Mojo->new; |
131 |
my $t = Test::Mojo->new; |
142 |
|
132 |
|
143 |
$t->get_ok('/query')->status_is(200) |
133 |
$t->get_ok('/query?_page=2&_per_page=3&firstname=Manuel&surname=Cohen%20Arazi')->status_is(200) |
144 |
->json_is( '/filtered_params' => |
134 |
->json_is( '/filtered_params' => |
145 |
{ firstname => 'Manuel', surname => 'Cohen Arazi' } ) |
135 |
{ firstname => 'Manuel', surname => 'Cohen Arazi' } ) |
146 |
->json_is( '/reserved_params' => { _page => 2, _per_page => 3 } ); |
136 |
->json_is( '/reserved_params' => { _page => 2, _per_page => 3 } ); |
147 |
|
137 |
|
148 |
$t->get_ok('/query_full')->status_is(200) |
138 |
$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) |
149 |
->json_is( |
139 |
->json_is( |
150 |
'/filtered_params' => { |
140 |
'/filtered_params' => { |
151 |
firstname => 'Manuel', |
141 |
firstname => 'Manuel', |
Lines 157-162
subtest 'extract_reserved_params() tests' => sub {
Link Here
|
157 |
_per_page => 3, |
147 |
_per_page => 3, |
158 |
_match => 'exact', |
148 |
_match => 'exact', |
159 |
_order_by => 'blah' |
149 |
_order_by => 'blah' |
|
|
150 |
} ) |
151 |
->json_is( |
152 |
'/path_params' => { |
153 |
id => 'with', |
154 |
subid => 'path' |
160 |
} ); |
155 |
} ); |
161 |
|
156 |
|
162 |
}; |
157 |
}; |
163 |
- |
|
|