Merge branch 'develop' into staging

This commit is contained in:
Xavier J 2015-09-28 18:58:25 +02:00
commit 90baaebb13
16 changed files with 231 additions and 208 deletions

View file

@ -155,13 +155,13 @@ function onDocumentReady() { if (typeof L != 'undefined' && typeof L.drawLocal !
} }
});**/ });**/
}); });
map.spin(true); //map.spin(true);
$.ajax({ //$.ajax({
url: 'http://apicarto.coremaps.com/zoneville/api/beta/qp/mapservice', // url: 'http://apicarto.coremaps.com/zoneville/api/beta/qp/mapservice',
datatype: 'json', // datatype: 'json',
jsonCallback: 'getJson', // jsonCallback: 'getJson',
success: loadGeoJson // success: loadGeoJson
}); //});
window.geom_inter = {index: []}; window.geom_inter = {index: []};
function style(feature) { function style(feature) {

View file

@ -4,7 +4,7 @@ function get_position(){
var position; var position;
$.ajax({ $.ajax({
url: '/dossiers/'+dossier_id+'/carte/position', url: '/users/dossiers/'+dossier_id+'/carte/position',
dataType: 'json', dataType: 'json',
async: false async: false
}).done(function (data) { }).done(function (data) {

View file

@ -1,15 +1,16 @@
class CarteController < ApplicationController class Users::CarteController < ApplicationController
include DossierConcern include DossierConcern
def show def show
@dossier = current_dossier @dossier = current_dossier
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound
redirect_to url_for(controller: :siret, action: :error_dossier) redirect_to url_for(controller: :dossiers, action: :index)
end end
def save_ref_api_carto def save_ref_api_carto
dossier = current_dossier dossier = current_dossier
if dossier.ref_dossier_carto.blank?
if dossier.draft?
dossier.update_attributes(ref_dossier_carto: params[:ref_dossier]) dossier.update_attributes(ref_dossier_carto: params[:ref_dossier])
redirect_to url_for(controller: :description, action: :show, dossier_id: params[:dossier_id]) redirect_to url_for(controller: :description, action: :show, dossier_id: params[:dossier_id])
else else

View file

@ -46,7 +46,12 @@ class Users::DossiersController < UsersController
@dossier = Dossier.find(params[:id]) @dossier = Dossier.find(params[:id])
if checked_autorisation_donnees? if checked_autorisation_donnees?
@dossier.update_attributes(update_params) @dossier.update_attributes(update_params)
redirect_to url_for(controller: :description, action: :show, dossier_id: @dossier.id)
if @dossier.procedure.use_api_carto
redirect_to url_for(controller: :carte, action: :show, dossier_id: @dossier.id)
else
redirect_to url_for(controller: :description, action: :show, dossier_id: @dossier.id)
end
else else
@etablissement = @dossier.etablissement @etablissement = @dossier.etablissement
@entreprise = @dossier.entreprise.decorate @entreprise = @dossier.entreprise.decorate

View file

@ -7,14 +7,13 @@
.content .content
#map_qp{style: 'height:600px; width: 100%;'} #map_qp{style: 'height:600px; width: 100%;'}
= form_tag(url_for({controller: :carte, action: :save_ref_api_carto}), class: 'form-inline', method: 'POST') do = form_tag(url_for({controller: :carte, action: :save_ref_api_carto, dossier_id: @dossier.id}), class: 'form-inline', method: 'POST') do
%br %br
%input{type: 'hidden', value: '', name: 'ref_dossier', id: 'ref_dossier'} %input{type: 'hidden', value: '', name: 'ref_dossier', id: 'ref_dossier'}
%input{type: 'hidden', value: request.parameters[:back_url], name: 'back_url', id: 'back_url'}
-if request.parameters[:back_url] == 'recapitulatif' -if @dossier.draft?
=render partial: '/layouts/modifications_terminees'
-else
=render partial: '/layouts/etape_suivante' =render partial: '/layouts/etape_suivante'
-else
=render partial: '/layouts/modifications_terminees'
=render partial: 'carte_sources_JS' =render partial: 'carte_sources_JS'

View file

@ -24,6 +24,11 @@ Rails.application.routes.draw do
get '/demande' => 'demandes#show' get '/demande' => 'demandes#show'
post '/demande' => 'demandes#update' post '/demande' => 'demandes#update'
post '/commentaire' => 'commentaires#create' post '/commentaire' => 'commentaires#create'
get '/carte/position' => 'carte#get_position'
get '/carte' => 'carte#show'
post '/carte' => 'carte#save_ref_api_carto'
end end
resource :dossiers resource :dossiers

View file

@ -0,0 +1,5 @@
class AddUseAPICartoToProcedure < ActiveRecord::Migration
def change
add_column :procedures, :use_api_carto, :boolean, :default => false
end
end

View file

@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150923101000) do ActiveRecord::Schema.define(version: 20150928141512) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "plpgsql" enable_extension "plpgsql"
@ -118,9 +118,10 @@ ActiveRecord::Schema.define(version: 20150923101000) do
t.string "organisation" t.string "organisation"
t.string "direction" t.string "direction"
t.string "lien_demarche" t.string "lien_demarche"
t.datetime "created_at", null: false t.datetime "created_at", null: false
t.datetime "updated_at", null: false t.datetime "updated_at", null: false
t.boolean "test" t.boolean "test"
t.boolean "use_api_carto", default: false
end end
create_table "types_de_piece_justificative", force: :cascade do |t| create_table "types_de_piece_justificative", force: :cascade do |t|

View file

@ -1,108 +0,0 @@
require 'spec_helper'
RSpec.describe CarteController, type: :controller do
#NOT USED ACTUALY
# let(:bad_adresse) { 'babouba' }
#
# let(:dossier) { create(:dossier) }
# let!(:entreprise) { create(:entreprise, dossier: dossier) }
# let!(:etablissement) { create(:etablissement, dossier: dossier) }
# let(:dossier_id) { dossier.id }
# let(:bad_dossier_id) { Dossier.count + 10 }
# let(:ref_dossier) { 'IATRQPQY' }
# let(:adresse) { etablissement.adresse }
#
# describe 'GET #show' do
# it 'returns http success' do
# get :show, dossier_id: dossier_id
# expect(response).to have_http_status(:success)
# end
#
# it 'redirection vers start si mauvais dossier ID' do
# get :show, dossier_id: bad_dossier_id
# expect(response).to redirect_to(controller: :start, action: :error_dossier)
# end
# end
#
# describe 'POST #save_ref_api_carto' do
# context 'Aucune localisation n\'a jamais été enregistrée' do
# it do
# post :save_ref_api_carto, dossier_id: dossier_id, ref_dossier: ref_dossier, back_url: ''
# expect(response).to redirect_to("/dossiers/#{dossier_id}/description")
# end
# 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
# end
#
# context 'Enregistrement d\'un commentaire informant la modification' do
# subject { dossier.commentaires.last }
#
# it 'champs email' do
# expect(subject.email).to eq('Modification localisation')
# end
#
# it 'champs body' do
# expect(subject.body).to eq('La localisation de la demande a été modifiée. Merci de le prendre en compte.')
# end
#
# it 'champs dossier' do
# expect(subject.dossier.id).to eq(dossier_id)
# end
# end
#
# it 'Redirection vers la page récapitulatif' do
# expect(response).to redirect_to("/dossiers/#{dossier_id}/recapitulatif")
# end
# end
# end
#
# 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: {})
# get :get_position, dossier_id: dossier.id
# end
#
# subject { dossier.reload }
#
# 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
#
# 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
# expect(response.content_type).to eq('application/json')
# end
#
# it 'latitude' do
# expect(subject['lat']).to eq('48.870374')
# end
#
# it 'longitude' do
# expect(subject['lon']).to eq('2.306888')
# end
#
# it 'dossier_id' do
# expect(subject['dossier_id']).to eq(dossier.id.to_s)
# end
# end
# end
end

View file

@ -0,0 +1,106 @@
require 'spec_helper'
RSpec.describe Users::CarteController, type: :controller do
let(:bad_adresse) { 'babouba' }
let(:dossier) { create(:dossier, :with_user, :with_procedure) }
let!(:entreprise) { create(:entreprise, dossier: dossier) }
let!(:etablissement) { create(:etablissement, dossier: dossier) }
let(:dossier_id) { dossier.id }
let(:bad_dossier_id) { Dossier.count + 1000 }
let(:ref_dossier_carto) { 'IATRQPQY' }
let(:adresse) { etablissement.adresse }
describe 'GET #show' do
it 'returns http success' do
get :show, dossier_id: dossier_id
expect(response).to have_http_status(:success)
end
it 'redirection vers la liste des dossiers du user si dossier ID n\'existe pas' do
get :show, dossier_id: bad_dossier_id
expect(response).to redirect_to(controller: :dossiers, action: :index)
end
end
describe 'POST #save_ref_api_carto' do
context 'Aucune localisation n\'a jamais été enregistrée' do
it do
post :save_ref_api_carto, dossier_id: dossier_id, ref_dossier_carto: ref_dossier_carto
expect(response).to redirect_to("/users/dossiers/#{dossier_id}/description")
end
end
context 'En train de modifier la localisation' do
let(:dossier) { create(:dossier, :with_procedure, :with_user, ref_dossier_carto: ref_dossier_carto, state: 'proposed') }
before do
post :save_ref_api_carto, dossier_id: dossier_id, ref_dossier_carto: ref_dossier_carto
end
context 'Enregistrement d\'un commentaire informant la modification' do
subject { dossier.commentaires.last }
it 'champs email' do
expect(subject.email).to eq('Modification localisation')
end
it 'champs body' do
expect(subject.body).to eq('La localisation de la demande a été modifiée. Merci de le prendre en compte.')
end
it 'champs dossier' do
expect(subject.dossier.id).to eq(dossier_id)
end
end
it 'Redirection vers la page récapitulatif' do
expect(response).to redirect_to("/users/dossiers/#{dossier_id}/recapitulatif")
end
end
end
describe '#get_position' do
context 'Geocodeur renvoie des positions nil' do
let(:etablissement) { create(:etablissement, adresse: bad_adresse) }
let(:dossier) { create(:dossier, :with_procedure, :with_user, 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: {})
get :get_position, dossier_id: dossier.id
end
subject { dossier.reload }
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
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
expect(response.content_type).to eq('application/json')
end
it 'latitude' do
expect(subject['lat']).to eq('48.870374')
end
it 'longitude' do
expect(subject['lon']).to eq('2.306888')
end
it 'dossier_id' do
expect(subject['dossier_id']).to eq(dossier.id.to_s)
end
end
end
end

View file

@ -16,8 +16,11 @@ describe Users::DossiersController, type: :controller do
it { is_expected.to have_http_status(:success) } it { is_expected.to have_http_status(:success) }
end end
end end
let(:dossier) { create(:dossier, :with_entreprise, :with_procedure, user: user) }
let(:procedure) { create(:procedure) }
let(:use_api_carto) { false }
let(:procedure) { create(:procedure, use_api_carto: use_api_carto) }
let(:dossier) { create(:dossier, :with_entreprise, user: user, procedure: procedure) }
let(:dossier_id) { dossier.id } let(:dossier_id) { dossier.id }
let(:siret_not_found) { 999_999_999_999 } let(:siret_not_found) { 999_999_999_999 }
@ -132,8 +135,22 @@ describe Users::DossiersController, type: :controller do
end end
context 'when Checkbox is checked' do context 'when Checkbox is checked' do
let(:autorisation_donnees) { '1' } let(:autorisation_donnees) { '1' }
it 'redirects to demande' do
expect(response).to redirect_to(controller: :description, action: :show, dossier_id: dossier.id) context 'procedure not use api carto' do
it 'redirects to demande' do
expect(response).to redirect_to(controller: :description, action: :show, dossier_id: dossier.id)
end
end
context 'procedure use api carto' do
let(:use_api_carto) { true }
before do
put :update, id: dossier_id, dossier: { autorisation_donnees: autorisation_donnees }
end
it 'redirects to carte' do
expect(response).to redirect_to(controller: :carte, action: :show, dossier_id: dossier.id)
end
end end
it 'update dossier' do it 'update dossier' do

View file

@ -1,76 +0,0 @@
require 'spec_helper'
feature 'Carte#Show Page' do
#NOT USED ACTUALY
# let(:dossier) { create(:dossier) }
# let(:dossier_id) { dossier.id }
#
# before do
# visit "/dossiers/#{dossier_id}/carte"
# end
#
# context 'sur la page de la carte d\'une demande' do
# scenario 'le formulaire envoie vers /dossiers/:dossier_id/carte en #POST' do
# expect(page).to have_selector("form[action='/dossiers/#{dossier_id}/carte'][method=post]")
# end
#
# scenario 'la page des sources CSS de l\'API carto est chargée' do
# expect(page).to have_selector('#sources_CSS_api_carto')
# end
#
# scenario 'la page des sources JS de l\'API carto est chargée' do
# expect(page).to have_selector('#sources_JS_api_carto')
# end
#
# scenario 'la carte est bien présente' do
# expect(page).to have_selector('#map_qp')
# end
#
# context 'présence des inputs hidden' do
# scenario 'stockage de la référence du dossie de l\'API carto' do
# expect(page).to have_selector('input[type=hidden][id=ref_dossier][name=ref_dossier]')
# end
#
# scenario 'stockage de l\'URL back si elle existe' do
# expect(page).to have_selector('input[type=hidden][id=back_url][name=back_url]')
# end
# end
#
# context 'si la page précédente n\'est pas recapitulatif' do
# scenario 'le bouton "Etape suivante" est présent' do
# expect(page).to have_selector('#etape_suivante')
# end
#
# scenario 'le bouton Etape suivante possède un onclick correct' do
# expect(page).to have_selector('input[type=submit][id=etape_suivante][onclick=\'submit_check_draw(event)\']')
# end
# end
#
# context 'si la page précédente est recapitularif' do
# before do
# visit "/dossiers/#{dossier_id}/carte?back_url=recapitulatif"
# end
#
# scenario 'le bouton "Etape suivante" n\'est pas présent' do
# expect(page).to_not have_selector('#etape_suivante')
# end
#
# scenario 'input hidden back_url a pour valeur le params GET' do
# expect(page).to have_selector('input[type=hidden][id=back_url][value=recapitulatif]')
# end
#
# scenario 'le bouton "Modification terminé" est présent' do
# expect(page).to have_selector('#modification_terminee')
# end
#
# scenario 'le bouton Etape suivante possède un onclick correct' do
# expect(page).to have_selector('input[type=submit][id=modification_terminee][onclick=\'submit_check_draw(event)\']')
# end
#
# scenario 'le lien de retour au récapitulatif est présent' do
# expect(page).to have_selector("a[href='/dossiers/#{dossier_id}/recapitulatif']")
# end
# end
# end
end

View file

@ -0,0 +1,68 @@
require 'spec_helper'
describe 'users/carte/show.html.haml', type: :view do
let(:state) { 'draft' }
let(:dossier) { create(:dossier, :with_procedure, :with_user, state: state) }
let(:dossier_id) { dossier.id }
before do
assign(:dossier, dossier)
end
context 'sur la page de la carte d\'une demande' do
before do
render
end
it 'le formulaire envoie vers /users/dossiers/:dossier_id/carte en #POST' do
expect(rendered).to have_selector("form[action='/users/dossiers/#{dossier_id}/carte'][method=post]")
end
it 'la page des sources CSS de l\'API carto est chargée' do
expect(rendered).to have_selector('#sources_CSS_api_carto')
end
it 'la page des sources JS de l\'API carto est chargée' do
expect(rendered).to have_selector('#sources_JS_api_carto')
end
it 'la carte est bien présente' do
expect(rendered).to have_selector('#map_qp')
end
context 'présence des inputs hidden' do
it 'stockage de la référence du dossie de l\'API carto' do
expect(rendered).to have_selector('input[type=hidden][id=ref_dossier][name=ref_dossier]')
end
end
context 'si la page précédente n\'est pas recapitulatif' do
it 'le bouton "Etape suivante" est présent' do
expect(rendered).to have_selector('#etape_suivante')
end
it 'le bouton Etape suivante possède un onclick correct' do
expect(rendered).to have_selector('input[type=submit][id=etape_suivante][onclick=\'submit_check_draw(event)\']')
end
end
context 'si la page précédente est recapitularif' do
let(:state) { 'proposed' }
it 'le bouton "Etape suivante" n\'est pas présent' do
expect(rendered).to_not have_selector('#etape_suivante')
end
it 'le bouton "Modification terminé" est présent' do
expect(rendered).to have_selector('#modification_terminee')
end
it 'le bouton "Modification terminé" possède un onclick correct' do
expect(rendered).to have_selector('input[type=submit][id=modification_terminee][onclick=\'submit_check_draw(event)\']')
end
it 'le lien de retour au récapitulatif est présent' do
expect(rendered).to have_selector("a[href='/users/dossiers/#{dossier_id}/recapitulatif']")
end
end
end
end