Remove ApiAdresse::Geocodeur
This commit is contained in:
parent
d68aca545a
commit
22088b167d
5 changed files with 31 additions and 36 deletions
|
@ -10,7 +10,9 @@ class Ban::SearchController < ApplicationController
|
|||
end
|
||||
|
||||
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?
|
||||
lon = point.x.to_s
|
||||
|
|
|
@ -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
|
|
@ -243,7 +243,7 @@ class Dossier < ApplicationRecord
|
|||
|
||||
def geo_position
|
||||
if etablissement.present?
|
||||
point = ApiAdresse::Geocodeur.convert_adresse_to_point(etablissement.geo_adresse)
|
||||
point = ApiAdresse::PointAdapter.new(etablissement.geo_adresse).geocode
|
||||
end
|
||||
|
||||
lon = "2.428462"
|
||||
|
|
|
@ -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
|
27
spec/lib/api_adresse/point_adapter_spec.rb
Normal file
27
spec/lib/api_adresse/point_adapter_spec.rb
Normal 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
|
Loading…
Reference in a new issue