Revu de code de la partie "/dossiers/dossier_id:/carte" :
/app/controllers/carte_controller.rb - l10/11 @dossier.update_attributes() - l27 : le @dossier ne semble pas necessaire - l32 : update attributes Ajouter : def dossier_id params[:dossier_id] end /spec/controllers/carte_controller_spec.rb - l 11/16 : utiliser nouvelle syntaxe pour les hashs : get :show, dossier_id: dossier_id - l32 bancal : Commentaire.last.id, en theorie tu n'as jamais besoin d'écrire de requête sql dans tes tests l36 subject { Commentaire.last } - l64, le cas ou c'est en erreur n'est pas testé (le géocodeur renvoie nil)
This commit is contained in:
parent
6e2c0f733c
commit
cfee2a6ddf
4 changed files with 59 additions and 24 deletions
|
@ -47,10 +47,17 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
position = get_position();
|
position = get_position();
|
||||||
|
position_zoom = 13;
|
||||||
|
|
||||||
|
if (position.lat == '0' && position.lon == '0'){
|
||||||
|
position.lon = '2.428462';
|
||||||
|
position.lat = '46.538192';
|
||||||
|
position_zoom = 6;
|
||||||
|
}
|
||||||
|
|
||||||
map = L.map(mapId, {
|
map = L.map(mapId, {
|
||||||
center: new L.LatLng(position.lat, position.lon),
|
center: new L.LatLng(position.lat, position.lon),
|
||||||
zoom: 13,
|
zoom: position_zoom,
|
||||||
layers: [OSM],
|
layers: [OSM],
|
||||||
photonControl: true,
|
photonControl: true,
|
||||||
photonControlOptions: photonControlOptions,
|
photonControlOptions: photonControlOptions,
|
||||||
|
|
|
@ -1,21 +1,23 @@
|
||||||
class CarteController < ApplicationController
|
class CarteController < ApplicationController
|
||||||
|
include DossierConcern
|
||||||
|
centre_de_la_France = 'Vesdun'
|
||||||
|
|
||||||
def show
|
def show
|
||||||
@dossier = Dossier.find(params[:dossier_id])
|
@dossier = current_dossier
|
||||||
rescue
|
rescue
|
||||||
redirect_to url_for({controller: :start, action: :error_dossier})
|
redirect_to url_for({controller: :start, action: :error_dossier})
|
||||||
end
|
end
|
||||||
|
|
||||||
def save_ref_api_carto
|
def save_ref_api_carto
|
||||||
@dossier = Dossier.find(params[:dossier_id])
|
dossier = current_dossier
|
||||||
@dossier.ref_dossier = params[:ref_dossier]
|
dossier.update_attributes(ref_dossier: params[:ref_dossier])
|
||||||
@dossier.save
|
|
||||||
|
|
||||||
if params[:back_url] == 'recapitulatif'
|
if params[:back_url] == 'recapitulatif'
|
||||||
@commentaire = Commentaire.create
|
commentaire = Commentaire.new
|
||||||
@commentaire.email = 'Modification localisation'
|
commentaire.email = 'Modification localisation'
|
||||||
@commentaire.body = 'La localisation de la demande a été modifiée. Merci de le prendre en compte.'
|
commentaire.body = 'La localisation de la demande a été modifiée. Merci de le prendre en compte.'
|
||||||
@commentaire.dossier = @dossier
|
commentaire.dossier = dossier
|
||||||
@commentaire.save
|
commentaire.save
|
||||||
|
|
||||||
redirect_to url_for({controller: :recapitulatif, action: :show, :dossier_id => params[:dossier_id]})
|
redirect_to url_for({controller: :recapitulatif, action: :show, :dossier_id => params[:dossier_id]})
|
||||||
else
|
else
|
||||||
|
@ -24,17 +26,18 @@ class CarteController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_position
|
def get_position
|
||||||
@dossier = Dossier.find(params[:dossier_id])
|
dossier = current_dossier
|
||||||
|
|
||||||
if @dossier.position_lat == nil
|
if dossier.position_lat == nil
|
||||||
tmp_position = Carto::Geocodeur.convert_adresse_to_point(@dossier.etablissement.adresse.gsub("\r\n", ' '))
|
tmp_position = Carto::Geocodeur.convert_adresse_to_point(dossier.etablissement.adresse.gsub("\r\n", ' '))
|
||||||
|
|
||||||
@dossier.position_lat = tmp_position.point.y
|
if tmp_position.point == nil
|
||||||
@dossier.position_lon = tmp_position.point.x
|
dossier.update_attributes(position_lat: '0', position_lon: '0')
|
||||||
|
else
|
||||||
@dossier.save
|
dossier.update_attributes(position_lat: tmp_position.point.y, position_lon: tmp_position.point.x)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
render json: { lon: @dossier.position_lon, lat: @dossier.position_lat, dossier_id: params[:dossier_id] }
|
render json: { lon: dossier.position_lon, lat: dossier.position_lat, dossier_id: params[:dossier_id] }
|
||||||
end
|
end
|
||||||
end
|
end
|
7
app/controllers/concerns/dossier_concern.rb
Normal file
7
app/controllers/concerns/dossier_concern.rb
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
module DossierConcern
|
||||||
|
|
||||||
|
def current_dossier
|
||||||
|
Dossier.find(params[:dossier_id])
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -5,6 +5,8 @@ RSpec.describe CarteController, type: :controller do
|
||||||
let(:bad_dossier_id){1000}
|
let(:bad_dossier_id){1000}
|
||||||
let(:ref_dossier){'IATRQPQY'}
|
let(:ref_dossier){'IATRQPQY'}
|
||||||
let(:adresse){'50 avenue des champs élysées Paris 75008'}
|
let(:adresse){'50 avenue des champs élysées Paris 75008'}
|
||||||
|
let(:bad_adresse){'babouba'}
|
||||||
|
|
||||||
|
|
||||||
describe "GET #show" do
|
describe "GET #show" do
|
||||||
it "returns http success" do
|
it "returns http success" do
|
||||||
|
@ -54,15 +56,31 @@ RSpec.describe CarteController, type: :controller do
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#get_position' do
|
describe '#get_position' do
|
||||||
before do
|
context 'Geocodeur renvoie des positions nil' do
|
||||||
stub_request(:get, "http://api-adresse.data.gouv.fr/search?limit=1&q=#{adresse}").
|
before do
|
||||||
to_return(:status => 200, :body => '{"query": "50 avenue des champs \u00e9lys\u00e9es Paris 75008", "version": "draft", "licence": "ODbL 1.0", "features": [{"geometry": {"coordinates": [2.306888, 48.870374], "type": "Point"}, "type": "Feature", "properties": {"city": "Paris", "label": "50 Avenue des Champs \u00c9lys\u00e9es 75008 Paris", "housenumber": "50", "id": "ADRNIVX_0000000270748251", "postcode": "75008", "name": "50 Avenue des Champs \u00c9lys\u00e9es", "citycode": "75108", "context": "75, \u00cele-de-France", "score": 0.9054545454545454, "type": "housenumber"}}], "type": "FeatureCollection", "attribution": "BAN"}', :headers => {})
|
stub_request(:get, "http://api-adresse.data.gouv.fr/search?limit=1&q=#{bad_adresse}").
|
||||||
get :get_position, :dossier_id => dossier_id
|
to_return(:status => 200, :body => '{"query": "babouba", "version": "draft", "licence": "ODbL 1.0", "features": [], "type": "FeatureCollection", "attribution": "BAN"}', :headers => {})
|
||||||
|
|
||||||
|
@tmp_dossier = Dossier.create()
|
||||||
|
Etablissement.create(adresse: bad_adresse, dossier: @tmp_dossier)
|
||||||
|
get :get_position, :dossier_id => @tmp_dossier.id
|
||||||
|
end
|
||||||
|
|
||||||
|
subject{Dossier.find(@tmp_dossier.id)}
|
||||||
|
|
||||||
|
it 'on enregistre des coordonnées lat et lon à 0' do
|
||||||
|
expect(subject.position_lat).to eq('0')
|
||||||
|
expect(subject.position_lon).to eq('0')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
#TODO Test carto geocodeur ne revoit rien / nil
|
|
||||||
|
|
||||||
context 'retour d\'un fichier JSON avec 3 attributs' do
|
context 'retour d\'un fichier JSON avec 3 attributs' do
|
||||||
|
before do
|
||||||
|
stub_request(:get, "http://api-adresse.data.gouv.fr/search?limit=1&q=#{adresse}").
|
||||||
|
to_return(:status => 200, :body => '{"query": "50 avenue des champs \u00e9lys\u00e9es Paris 75008", "version": "draft", "licence": "ODbL 1.0", "features": [{"geometry": {"coordinates": [2.306888, 48.870374], "type": "Point"}, "type": "Feature", "properties": {"city": "Paris", "label": "50 Avenue des Champs \u00c9lys\u00e9es 75008 Paris", "housenumber": "50", "id": "ADRNIVX_0000000270748251", "postcode": "75008", "name": "50 Avenue des Champs \u00c9lys\u00e9es", "citycode": "75108", "context": "75, \u00cele-de-France", "score": 0.9054545454545454, "type": "housenumber"}}], "type": "FeatureCollection", "attribution": "BAN"}', :headers => {})
|
||||||
|
|
||||||
|
get :get_position, :dossier_id => dossier_id
|
||||||
|
end
|
||||||
subject {JSON.parse(response.body)}
|
subject {JSON.parse(response.body)}
|
||||||
|
|
||||||
it 'format JSON valide' do
|
it 'format JSON valide' do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue