Permalink
Browse files

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

…tance_unit key
  • Loading branch information...
1 parent 66916db commit 9e1f2013411215adfddd48debdd41c5285657712 @autarch autarch committed Oct 14, 2012
Showing with 23 additions and 7 deletions.
  1. +3 −5 lib/VegGuide/Controller/Search.pm
  2. +20 −2 t/rest-api/Search.t
@@ -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;
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'
);
}
@@ -280,6 +292,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',

0 comments on commit 9e1f201

Please sign in to comment.