Skip to content

Commit 3a565fe

Browse files
authored
Merge pull request #1219 from metacpan/haarg/fix-fake-rating
fix parsing of rating end points
2 parents 1621321 + 6137a2a commit 3a565fe

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

lib/MetaCPAN/Server/Controller/Rating.pm

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,18 @@ sub _mapping : Path('_mapping') : Args(0) {
2828
$c->detach('/not_found');
2929
}
3030

31-
sub find : Path('_search') : Args(0) {
31+
sub find : Path('_search') : Args(0) : ActionClass('~Deserialize') {
3232
my ( $self, $c, $scroll ) = @_;
3333

3434
my @hits;
3535

3636
# fake results for MetaCPAN::Client so it doesn't fail its tests
37-
if ( ( $c->req->user_agent // '' )
38-
=~ m{^MetaCPAN::Client-testing/([0-9.]+)} )
39-
{
37+
if ( ( $c->req->user_agent // '' ) =~ m{^MetaCPAN::Client/([0-9.]+)} ) {
4038
if ( $1 <= 2.031001 ) {
41-
my $query = $c->read_param('query');
39+
my $query = $c->req->data->{'query'};
4240
if ( $query
43-
&& $query->[0]
44-
&& $query->[0]{term}
45-
&& ( $query->[0]{term}{distribution} // '' ) eq 'Moose' )
41+
&& $query->{term}
42+
&& ( $query->{term}{distribution} // '' ) eq 'Moose' )
4643
{
4744

4845
push @hits,
@@ -72,7 +69,7 @@ sub find : Path('_search') : Args(0) {
7269
} );
7370
}
7471

75-
sub all : Path('') : Args(0) {
72+
sub all : Path('') : Args(0) : ActionClass('~Deserialize') {
7673
my ( $self, $c ) = @_;
7774
$c->forward('find');
7875
}

t/server/controller/rating.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ test_psgi app, sub {
9292
ok(
9393
$res = $cb->(
9494
POST '/rating/_search',
95-
'User-Agent' => 'MetaCPAN::Client-testing/2.031001',
95+
'User-Agent' => 'MetaCPAN::Client/2.031001',
9696
Content => '{"query":{"term":{"distribution":"Moose"}}}',
9797
),
9898
'POST /rating with MetaCPAN::Client test UA'

0 commit comments

Comments
 (0)