refactor carte controller
This commit is contained in:
parent
ef69fa453c
commit
67a4ff2519
2 changed files with 22 additions and 21 deletions
|
@ -4,24 +4,25 @@ class CarteController < ApplicationController
|
|||
|
||||
def show
|
||||
@dossier = current_dossier
|
||||
rescue
|
||||
redirect_to url_for({controller: :start, action: :error_dossier})
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
redirect_to url_for(controller: :start, action: :error_dossier)
|
||||
end
|
||||
|
||||
def save_ref_api_carto
|
||||
dossier = current_dossier
|
||||
dossier.update_attributes(ref_dossier: params[:ref_dossier])
|
||||
|
||||
if params[:back_url] == 'recapitulatif'
|
||||
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
|
||||
if dossier.ref_dossier.blank?
|
||||
dossier.update_attributes(ref_dossier: params[:ref_dossier])
|
||||
redirect_to url_for({controller: :description, action: :show, :dossier_id => params[:dossier_id]})
|
||||
else
|
||||
commentaire_params = {
|
||||
email: 'Modification localisation',
|
||||
body: 'La localisation de la demande a été modifiée. Merci de le prendre en compte.',
|
||||
dossier_id: dossier.id
|
||||
}
|
||||
commentaire = Commentaire.new commentaire_params
|
||||
commentaire.save
|
||||
redirect_to url_for({controller: :recapitulatif, action: :show, :dossier_id => params[:dossier_id]})
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ RSpec.describe CarteController, type: :controller do
|
|||
|
||||
it 'redirection vers start si mauvais dossier ID' do
|
||||
get :show, dossier_id: bad_dossier_id
|
||||
expect(response).to redirect_to('/start/error_dossier')
|
||||
expect(response).to redirect_to(controller: :start, action: :error_dossier)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -35,12 +35,13 @@ RSpec.describe CarteController, type: :controller do
|
|||
end
|
||||
|
||||
context 'En train de modifier la localisation' do
|
||||
let(:dossier) { create(:dossier, ref_dossier: ref_dossier)}
|
||||
before do
|
||||
post :save_ref_api_carto, :dossier_id => dossier_id, :ref_dossier => ref_dossier, :back_url => 'recapitulatif'
|
||||
post :save_ref_api_carto, :dossier_id => dossier_id, :ref_dossier => ref_dossier
|
||||
end
|
||||
|
||||
context 'Enregistrement d\'un commentaire informant la modification' do
|
||||
subject { Commentaire.last }
|
||||
subject { dossier.commentaires.last }
|
||||
|
||||
it 'champs email' do
|
||||
expect(subject.email).to eq('Modification localisation')
|
||||
|
@ -63,16 +64,15 @@ RSpec.describe CarteController, type: :controller do
|
|||
|
||||
describe '#get_position' do
|
||||
context 'Geocodeur renvoie des positions nil' do
|
||||
let(:etablissement) { create(:etablissement, adresse: bad_adresse)}
|
||||
let(:dossier) {create(:dossier, etablissement: etablissement)}
|
||||
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
|
||||
get :get_position, :dossier_id => dossier.id
|
||||
end
|
||||
|
||||
subject{Dossier.find(@tmp_dossier.id)}
|
||||
subject { dossier.reload }
|
||||
|
||||
it 'on enregistre des coordonnées lat et lon à 0' do
|
||||
expect(subject.position_lat).to eq('0')
|
||||
|
|
Loading…
Reference in a new issue