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_zoom = 13;
|
||||
|
||||
if (position.lat == '0' && position.lon == '0'){
|
||||
position.lon = '2.428462';
|
||||
position.lat = '46.538192';
|
||||
position_zoom = 6;
|
||||
}
|
||||
|
||||
map = L.map(mapId, {
|
||||
center: new L.LatLng(position.lat, position.lon),
|
||||
zoom: 13,
|
||||
zoom: position_zoom,
|
||||
layers: [OSM],
|
||||
photonControl: true,
|
||||
photonControlOptions: photonControlOptions,
|
||||
|
|
|
@ -1,21 +1,23 @@
|
|||
class CarteController < ApplicationController
|
||||
include DossierConcern
|
||||
centre_de_la_France = 'Vesdun'
|
||||
|
||||
def show
|
||||
@dossier = Dossier.find(params[:dossier_id])
|
||||
@dossier = current_dossier
|
||||
rescue
|
||||
redirect_to url_for({controller: :start, action: :error_dossier})
|
||||
end
|
||||
|
||||
def save_ref_api_carto
|
||||
@dossier = Dossier.find(params[:dossier_id])
|
||||
@dossier.ref_dossier = params[:ref_dossier]
|
||||
@dossier.save
|
||||
dossier = current_dossier
|
||||
dossier.update_attributes(ref_dossier: params[:ref_dossier])
|
||||
|
||||
if params[:back_url] == 'recapitulatif'
|
||||
@commentaire = Commentaire.create
|
||||
@commentaire.email = 'Modification localisation'
|
||||
@commentaire.body = 'La localisation de la demande a été modifiée. Merci de le prendre en compte.'
|
||||
@commentaire.dossier = @dossier
|
||||
@commentaire.save
|
||||
commentaire = Commentaire.new
|
||||
commentaire.email = 'Modification localisation'
|
||||
commentaire.body = 'La localisation de la demande a été modifiée. Merci de le prendre en compte.'
|
||||
commentaire.dossier = dossier
|
||||
commentaire.save
|
||||
|
||||
redirect_to url_for({controller: :recapitulatif, action: :show, :dossier_id => params[:dossier_id]})
|
||||
else
|
||||
|
@ -24,17 +26,18 @@ class CarteController < ApplicationController
|
|||
end
|
||||
|
||||
def get_position
|
||||
@dossier = Dossier.find(params[:dossier_id])
|
||||
dossier = current_dossier
|
||||
|
||||
if @dossier.position_lat == nil
|
||||
tmp_position = Carto::Geocodeur.convert_adresse_to_point(@dossier.etablissement.adresse.gsub("\r\n", ' '))
|
||||
if dossier.position_lat == nil
|
||||
tmp_position = Carto::Geocodeur.convert_adresse_to_point(dossier.etablissement.adresse.gsub("\r\n", ' '))
|
||||
|
||||
@dossier.position_lat = tmp_position.point.y
|
||||
@dossier.position_lon = tmp_position.point.x
|
||||
|
||||
@dossier.save
|
||||
if tmp_position.point == nil
|
||||
dossier.update_attributes(position_lat: '0', position_lon: '0')
|
||||
else
|
||||
dossier.update_attributes(position_lat: tmp_position.point.y, position_lon: tmp_position.point.x)
|
||||
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
|
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(:ref_dossier){'IATRQPQY'}
|
||||
let(:adresse){'50 avenue des champs élysées Paris 75008'}
|
||||
let(:bad_adresse){'babouba'}
|
||||
|
||||
|
||||
describe "GET #show" do
|
||||
it "returns http success" do
|
||||
|
@ -54,15 +56,31 @@ RSpec.describe CarteController, type: :controller do
|
|||
end
|
||||
|
||||
describe '#get_position' 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
|
||||
context 'Geocodeur renvoie des positions nil' do
|
||||
before do
|
||||
stub_request(:get, "http://api-adresse.data.gouv.fr/search?limit=1&q=#{bad_adresse}").
|
||||
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
|
||||
|
||||
#TODO Test carto geocodeur ne revoit rien / nil
|
||||
|
||||
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)}
|
||||
|
||||
it 'format JSON valide' do
|
||||
|
|
Loading…
Add table
Reference in a new issue