Use geocoder
This commit is contained in:
parent
14295db9ad
commit
4edc7b00cf
6 changed files with 43 additions and 3 deletions
1
Gemfile
1
Gemfile
|
@ -29,6 +29,7 @@ gem 'flipper-active_record'
|
||||||
gem 'flipper-ui'
|
gem 'flipper-ui'
|
||||||
gem 'fog-openstack'
|
gem 'fog-openstack'
|
||||||
gem 'font-awesome-rails'
|
gem 'font-awesome-rails'
|
||||||
|
gem 'geocoder'
|
||||||
gem 'gon'
|
gem 'gon'
|
||||||
gem 'graphiql-rails'
|
gem 'graphiql-rails'
|
||||||
gem 'graphql'
|
gem 'graphql'
|
||||||
|
|
|
@ -232,6 +232,7 @@ GEM
|
||||||
font-awesome-rails (4.7.0.4)
|
font-awesome-rails (4.7.0.4)
|
||||||
railties (>= 3.2, < 6.0)
|
railties (>= 3.2, < 6.0)
|
||||||
formatador (0.2.5)
|
formatador (0.2.5)
|
||||||
|
geocoder (1.6.0)
|
||||||
globalid (0.4.2)
|
globalid (0.4.2)
|
||||||
activesupport (>= 4.2.0)
|
activesupport (>= 4.2.0)
|
||||||
gon (6.2.1)
|
gon (6.2.1)
|
||||||
|
@ -743,6 +744,7 @@ DEPENDENCIES
|
||||||
flipper-ui
|
flipper-ui
|
||||||
fog-openstack
|
fog-openstack
|
||||||
font-awesome-rails
|
font-awesome-rails
|
||||||
|
geocoder
|
||||||
gon
|
gon
|
||||||
graphiql-rails
|
graphiql-rails
|
||||||
graphql
|
graphql
|
||||||
|
|
|
@ -343,7 +343,7 @@ class Dossier < ApplicationRecord
|
||||||
|
|
||||||
def geo_position
|
def geo_position
|
||||||
if etablissement.present?
|
if etablissement.present?
|
||||||
point = ApiAdresse::PointAdapter.new(etablissement.geo_adresse).geocode
|
point = Geocoder.search(etablissement.geo_adresse).first
|
||||||
end
|
end
|
||||||
|
|
||||||
lon = "2.428462"
|
lon = "2.428462"
|
||||||
|
@ -351,8 +351,7 @@ class Dossier < ApplicationRecord
|
||||||
zoom = "13"
|
zoom = "13"
|
||||||
|
|
||||||
if point.present?
|
if point.present?
|
||||||
lon = point.x.to_s
|
lat, lon = point.coordinates.map(&:to_s)
|
||||||
lat = point.y.to_s
|
|
||||||
end
|
end
|
||||||
|
|
||||||
{ lon: lon, lat: lat, zoom: zoom }
|
{ lon: lon, lat: lat, zoom: zoom }
|
||||||
|
|
1
config/initializers/geocoder.rb
Normal file
1
config/initializers/geocoder.rb
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Geocoder.configure(lookup: :ban_data_gouv_fr)
|
|
@ -1084,4 +1084,39 @@ describe Dossier do
|
||||||
expect { expired_brouillon.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
expect { expired_brouillon.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe '#geo_position' do
|
||||||
|
let(:lat) { "46.538192" }
|
||||||
|
let(:lon) { "2.428462" }
|
||||||
|
let(:zoom) { "13" }
|
||||||
|
|
||||||
|
let(:etablissement_geo_adresse_lat) { "40.7143528" }
|
||||||
|
let(:etablissement_geo_adresse_lon) { "-74.0059731" }
|
||||||
|
|
||||||
|
let(:result) { { lat: lat, lon: lon, zoom: zoom } }
|
||||||
|
let(:dossier) { create(:dossier) }
|
||||||
|
|
||||||
|
it 'should geolocate' do
|
||||||
|
expect(dossier.geo_position).to eq(result)
|
||||||
|
end
|
||||||
|
|
||||||
|
context 'with etablissement' do
|
||||||
|
before do
|
||||||
|
Geocoder::Lookup::Test.add_stub(
|
||||||
|
dossier.etablissement.geo_adresse, [
|
||||||
|
{
|
||||||
|
'coordinates' => [etablissement_geo_adresse_lat.to_f, etablissement_geo_adresse_lon.to_f]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:dossier) { create(:dossier, :with_entreprise) }
|
||||||
|
let(:result) { { lat: etablissement_geo_adresse_lat, lon: etablissement_geo_adresse_lon, zoom: zoom } }
|
||||||
|
|
||||||
|
it 'should geolocate' do
|
||||||
|
expect(dossier.geo_position).to eq(result)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -152,6 +152,8 @@ RSpec.configure do |config|
|
||||||
ActionMailer::Base.deliveries.clear
|
ActionMailer::Base.deliveries.clear
|
||||||
|
|
||||||
ActiveStorage::Current.host = 'http://test.host'
|
ActiveStorage::Current.host = 'http://test.host'
|
||||||
|
|
||||||
|
Geocoder.configure(lookup: :test)
|
||||||
}
|
}
|
||||||
|
|
||||||
RSpec::Matchers.define :have_same_attributes_as do |expected, options|
|
RSpec::Matchers.define :have_same_attributes_as do |expected, options|
|
||||||
|
|
Loading…
Reference in a new issue