Skip to content

Commit

Permalink
Merge pull request pinballmap#1275 from RyanTG/master
Browse files Browse the repository at this point in the history
bows to rubocop
  • Loading branch information
RyanTG committed Jan 22, 2021
2 parents 437ccec + dfd1cf5 commit 5e829fa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 11 deletions.
4 changes: 2 additions & 2 deletions app/controllers/api/v1/locations_controller.rb
Expand Up @@ -138,7 +138,7 @@ def closest_by_lat_lon
max_distance = params[:max_distance] ||= MAX_MILES_TO_SEARCH_FOR_CLOSEST_LOCATION

except = params[:no_details] ? %i[country is_stern_army last_updated_by_user_id description region_id zone_id website phone] : nil

closest_locations = apply_scopes(Location).includes(:machines).near([params[:lat], params[:lon]], max_distance)

if !closest_locations.empty? && !params[:send_all_within_distance]
Expand All @@ -161,7 +161,7 @@ def closest_by_lat_lon
formats ['json']
def closest_by_address
max_distance = params[:max_distance] ||= MAX_MILES_TO_SEARCH_FOR_CLOSEST_LOCATION

except = params[:no_details] ? %i[country is_stern_army last_updated_by_user_id description region_id zone_id website phone] : nil

lat, lon = ''
Expand Down
16 changes: 7 additions & 9 deletions spec/requests/api/v1/locations_controller_spec.rb
Expand Up @@ -513,12 +513,11 @@
expect(locations[1]['id']).to eq(close_location_two.id)
expect(locations[2]['id']).to eq(close_location_one.id)
end

it 'respects no_details and shows fewer location fields' do
close_location_one = FactoryBot.create(:location, region: @region, lat: 45.49, lon: -122.63)
close_location_two = FactoryBot.create(:location, region: @region, lat: 45.49, lon: -122.631)
FactoryBot.create(:location, region: @region, lat: 45.49, lon: -122.63)
FactoryBot.create(:location, region: @region, lat: 5.49, lon: 22.63)

get '/api/v1/locations/closest_by_address.json', params: { address: '97202', send_all_within_distance: 1, no_details: 1 }

expect(response.body.scan('country').size).to eq(0)
Expand Down Expand Up @@ -603,13 +602,12 @@
expect(locations[1]['id']).to eq(close_location_two.id)
expect(locations[2]['id']).to eq(close_location_three.id)
end

it 'respects no_details and shows fewer location fields' do
close_location_one = FactoryBot.create(:location, region: @region, lat: 45.49, lon: -122.63)
close_location_two = FactoryBot.create(:location, region: @region, lat: 45.49, lon: -122.631)
closest_location = FactoryBot.create(:location, region: @region, lat: 45.49, lon: -122.63)
FactoryBot.create(:location, region: @region, lat: 5.49, lon: 22.63)
get '/api/v1/locations/closest_by_lat_lon.json', params: { lat: close_location_one.lat, lon: close_location_one.lon, send_all_within_distance: 1, no_details: 1 }

get '/api/v1/locations/closest_by_lat_lon.json', params: { lat: closest_location.lat, lon: closest_location.lon, send_all_within_distance: 1, no_details: 1 }

expect(response.body.scan('country').size).to eq(0)
expect(response.body.scan('is_stern_army').size).to eq(0)
Expand Down

0 comments on commit 5e829fa

Please sign in to comment.