|
Lines 80-85
get '/dbic_merge_sorting' => sub {
Link Here
|
| 80 |
$c->render( json => $attributes, status => 200 ); |
80 |
$c->render( json => $attributes, status => 200 ); |
| 81 |
}; |
81 |
}; |
| 82 |
|
82 |
|
|
|
83 |
get '/dbic_merge_sorting_single' => sub { |
| 84 |
my $c = shift; |
| 85 |
my $attributes = { a => 'a', b => 'b' }; |
| 86 |
$attributes = $c->dbic_merge_sorting( |
| 87 |
{ |
| 88 |
attributes => $attributes, |
| 89 |
params => { _match => 'exact', _order_by => '-uno' } |
| 90 |
} |
| 91 |
); |
| 92 |
$c->render( json => $attributes, status => 200 ); |
| 93 |
}; |
| 94 |
|
| 95 |
get '/dbic_merge_sorting_to_model' => sub { |
| 96 |
my $c = shift; |
| 97 |
my $attributes = { a => 'a', b => 'b' }; |
| 98 |
$attributes = $c->dbic_merge_sorting( |
| 99 |
{ |
| 100 |
attributes => $attributes, |
| 101 |
params => { _match => 'exact', _order_by => [ 'uno', '-dos', '+tres', ' cuatro' ] }, |
| 102 |
to_model => \&to_model |
| 103 |
} |
| 104 |
); |
| 105 |
$c->render( json => $attributes, status => 200 ); |
| 106 |
}; |
| 107 |
|
| 83 |
get '/build_query' => sub { |
108 |
get '/build_query' => sub { |
| 84 |
my $c = shift; |
109 |
my $c = shift; |
| 85 |
my ( $filtered_params, $reserved_params ) = |
110 |
my ( $filtered_params, $reserved_params ) = |
|
Lines 97-102
get '/build_query' => sub {
Link Here
|
| 97 |
}; |
122 |
}; |
| 98 |
}; |
123 |
}; |
| 99 |
|
124 |
|
|
|
125 |
sub to_model { |
| 126 |
my ($args) = @_; |
| 127 |
$args->{three} = delete $args->{tres} |
| 128 |
if exists $args->{tres}; |
| 129 |
return $args; |
| 130 |
} |
| 131 |
|
| 100 |
# The tests |
132 |
# The tests |
| 101 |
|
133 |
|
| 102 |
use Test::More tests => 3; |
134 |
use Test::More tests => 3; |
|
Lines 131-137
subtest 'extract_reserved_params() tests' => sub {
Link Here
|
| 131 |
|
163 |
|
| 132 |
subtest 'dbic_merge_sorting() tests' => sub { |
164 |
subtest 'dbic_merge_sorting() tests' => sub { |
| 133 |
|
165 |
|
| 134 |
plan tests => 5; |
166 |
plan tests => 15; |
| 135 |
|
167 |
|
| 136 |
my $t = Test::Mojo->new; |
168 |
my $t = Test::Mojo->new; |
| 137 |
|
169 |
|
|
Lines 145-150
subtest 'dbic_merge_sorting() tests' => sub {
Link Here
|
| 145 |
{ -asc => 'cuatro' } |
177 |
{ -asc => 'cuatro' } |
| 146 |
] |
178 |
] |
| 147 |
); |
179 |
); |
|
|
180 |
|
| 181 |
$t->get_ok('/dbic_merge_sorting_to_model')->status_is(200) |
| 182 |
->json_is( '/a' => 'a', 'Existing values are kept (a)' ) |
| 183 |
->json_is( '/b' => 'b', 'Existing values are kept (b)' )->json_is( |
| 184 |
'/order_by' => [ |
| 185 |
'uno', |
| 186 |
{ -desc => 'dos' }, |
| 187 |
{ -asc => 'three' }, |
| 188 |
{ -asc => 'cuatro' } |
| 189 |
] |
| 190 |
); |
| 191 |
|
| 192 |
$t->get_ok('/dbic_merge_sorting_single')->status_is(200) |
| 193 |
->json_is( '/a' => 'a', 'Existing values are kept (a)' ) |
| 194 |
->json_is( '/b' => 'b', 'Existing values are kept (b)' )->json_is( |
| 195 |
'/order_by' => { '-desc' => 'uno' } |
| 196 |
); |
| 148 |
}; |
197 |
}; |
| 149 |
|
198 |
|
| 150 |
subtest '_build_query_params_from_api' => sub { |
199 |
subtest '_build_query_params_from_api' => sub { |
| 151 |
- |
|
|