Fix bug get_position when établissement is nil
This commit is contained in:
parent
addeaab744
commit
d67d32e3c2
2 changed files with 20 additions and 1 deletions
|
@ -32,7 +32,8 @@ class Users::CarteController < UsersController
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_position
|
def get_position
|
||||||
point = Carto::Geocodeur.convert_adresse_to_point(current_user_dossier.etablissement.geo_adresse) rescue nil
|
etablissement = current_user_dossier.etablissement
|
||||||
|
point = Carto::Geocodeur.convert_adresse_to_point(etablissement.geo_adresse) unless etablissement.nil?
|
||||||
|
|
||||||
lon = '2.428462'
|
lon = '2.428462'
|
||||||
lat = '46.538192'
|
lat = '46.538192'
|
||||||
|
|
|
@ -179,6 +179,24 @@ shared_examples 'carte_controller_spec' do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#get_position' do
|
describe '#get_position' do
|
||||||
|
|
||||||
|
context 'when etablissement is nil' do
|
||||||
|
before do
|
||||||
|
dossier.update etablissement: nil
|
||||||
|
|
||||||
|
stub_request(:get, /http:\/\/api-adresse[.]data[.]gouv[.]fr\/search[?]limit=1&q=/)
|
||||||
|
.to_return(status: 200, body: '{"query": "babouba", "version": "draft", "licence": "ODbL 1.0", "features": [], "type": "FeatureCollection", "attribution": "BAN"}', headers: {})
|
||||||
|
get :get_position, params: {dossier_id: dossier.id}
|
||||||
|
end
|
||||||
|
|
||||||
|
subject { JSON.parse(response.body) }
|
||||||
|
|
||||||
|
it 'on enregistre des coordonnées lat et lon avec les valeurs par defaut' do
|
||||||
|
expect(subject['lat']).to eq('46.538192')
|
||||||
|
expect(subject['lon']).to eq('2.428462')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context 'Geocodeur renvoie les positions par defaut' do
|
context 'Geocodeur renvoie les positions par defaut' do
|
||||||
let(:etablissement) { create(:etablissement, adresse: bad_adresse, numero_voie: 'dzj', type_voie: 'fzjfk', nom_voie: 'hdidjkz', complement_adresse: 'fjef', code_postal: 'fjeiefk', localite: 'zjfkfz') }
|
let(:etablissement) { create(:etablissement, adresse: bad_adresse, numero_voie: 'dzj', type_voie: 'fzjfk', nom_voie: 'hdidjkz', complement_adresse: 'fjef', code_postal: 'fjeiefk', localite: 'zjfkfz') }
|
||||||
let(:dossier) { create(:dossier, etablissement: etablissement) }
|
let(:dossier) { create(:dossier, etablissement: etablissement) }
|
||||||
|
|
Loading…
Reference in a new issue