Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Geographical searches now return distance as a number and include dis…

…tance_unit key
  • Loading branch information...
commit 9e1f2013411215adfddd48debdd41c5285657712 1 parent 66916db
Dave Rolsky autarch authored
Showing with 23 additions and 7 deletions.
  1. +3 −5 lib/VegGuide/Controller/Search.pm
  2. +20 −2 t/rest-api/Search.t
8 lib/VegGuide/Controller/Search.pm
View
@@ -135,7 +135,8 @@ sub _search_rest_response {
my $path = shift;
my %rest = (
- entry_count => $search->count(),
+ entry_count => $search->count(),
+ distance_unit => $search->unit(),
);
my $country;
@@ -151,10 +152,7 @@ sub _search_rest_response {
unit => $search->unit(),
);
- my $with_units = $distance . ' ' . $search->unit();
- $with_units .= 's' unless $distance == 1;
-
- $entry_rest->{distance} = $with_units;
+ $entry_rest->{distance} = $distance;
push @{ $rest{entries} }, $entry_rest;
22 t/rest-api/Search.t
View
@@ -72,10 +72,16 @@ use_test_database();
is(
$entry->{distance},
- '0.2 miles',
+ '0.232580025603212',
'entry data has a distance key with the expected value'
);
+ is(
+ $search->{distance_unit},
+ 'mile',
+ 'distance_unit for search is mile'
+ );
+
is_deeply(
$entry->{user},
{
@@ -253,11 +259,17 @@ use_test_database();
'entry_count is same as the number of entries returned'
);
+ is(
+ $search->{distance_unit},
+ 'mile',
+ 'distance_unit for search is mile'
+ );
+
my $entry = $search->{entries}[0];
is(
$entry->{distance},
- '0.2 miles',
+ '0.232580025603212',
'entry data has a distance key with the expected value'
);
}
@@ -281,6 +293,12 @@ use_test_database();
my $uri = URI->new( $search->{uri} );
is(
+ $search->{distance_unit},
+ 'mile',
+ 'distance_unit for search is mile'
+ );
+
+ is(
$uri->query_param('unit'),
'km',
'unit query param is km for lat/long in Germany'
Please sign in to comment.
Something went wrong with that request. Please try again.