Remove ApiAdresse::Geocodeur

This commit is contained in:
gregoirenovel 2018-10-15 21:48:17 +02:00
parent d68aca545a
commit 22088b167d
5 changed files with 31 additions and 36 deletions

View file

@ -10,7 +10,9 @@ class Ban::SearchController < ApplicationController
end end
def get_address_point def get_address_point
point = ApiAdresse::Geocodeur.convert_adresse_to_point(params[:request]) request = params[:request]
point = ApiAdresse::PointAdapter.new(request).geocode
if point.present? if point.present?
lon = point.x.to_s lon = point.x.to_s

View file

@ -1,8 +0,0 @@
class ApiAdresse::Geocodeur
def self.convert_adresse_to_point(address)
ApiAdresse::PointAdapter.new(address).geocode
rescue RestClient::Exception, JSON::ParserError => e
Rails.logger.error(e.message)
nil
end
end

View file

@ -243,7 +243,7 @@ class Dossier < ApplicationRecord
def geo_position def geo_position
if etablissement.present? if etablissement.present?
point = ApiAdresse::Geocodeur.convert_adresse_to_point(etablissement.geo_adresse) point = ApiAdresse::PointAdapter.new(etablissement.geo_adresse).geocode
end end
lon = "2.428462" lon = "2.428462"

View file

@ -1,26 +0,0 @@
require 'spec_helper'
describe ApiAdresse::Geocodeur do
let(:address) { '50 av des champs elysees' }
describe '.convert_adresse_to_point', vcr: { cassette_name: 'api_adresse_octo' } do
it 'return a point' do
expect(described_class.convert_adresse_to_point(address).class).to eq(RGeo::Cartesian::PointImpl)
end
context 'when RestClient::Exception' do
before do
allow(ApiAdresse::API).to receive(:call).and_raise(RestClient::Exception)
end
it 'return nil' do
expect(described_class.convert_adresse_to_point(address)).to be_nil
end
end
context 'when JSON::ParserError' do
before do
allow_any_instance_of(ApiAdresse::PointAdapter).to receive(:geocode).and_raise(JSON::ParserError)
end
it 'return nil' do
expect(described_class.convert_adresse_to_point(address)).to be_nil
end
end
end
end

View file

@ -0,0 +1,27 @@
require 'spec_helper'
describe ApiAdresse::PointAdapter do
let(:address) { '50 av des champs elysees' }
describe '.geocode', vcr: { cassette_name: 'api_adresse_octo' } do
it 'return a point' do
expect(described_class.new(address).geocode.class).to eq(RGeo::Cartesian::PointImpl)
end
context 'when RestClient::Exception' do
before do
allow(ApiAdresse::API).to receive(:call).and_raise(RestClient::Exception)
end
it 'return nil' do
expect(described_class.new(address).geocode).to be_nil
end
end
context 'when JSON::ParserError' do
before do
allow(JSON).to receive(:parse).and_raise(JSON::ParserError)
end
it 'return nil' do
expect(described_class.new(address).geocode).to be_nil
end
end
end
end