Merge branch 'dev'

This commit is contained in:
gregoirenovel 2018-04-04 14:28:19 +02:00
commit 1b9e72bc3d
13 changed files with 121 additions and 36 deletions

View file

@ -92,7 +92,9 @@ class Users::DossiersController < UsersController
individual.update_column :gender, @facade.dossier.france_connect_information.gender individual.update_column :gender, @facade.dossier.france_connect_information.gender
individual.update_column :nom, @facade.dossier.france_connect_information.family_name individual.update_column :nom, @facade.dossier.france_connect_information.family_name
individual.update_column :prenom, @facade.dossier.france_connect_information.given_name individual.update_column :prenom, @facade.dossier.france_connect_information.given_name
individual.update_column :birthdate, @facade.dossier.france_connect_information.birthdate.iso8601
individual.birthdate = @facade.dossier.france_connect_information.birthdate
individual.save
end end
rescue ActiveRecord::RecordNotFound rescue ActiveRecord::RecordNotFound
@ -198,7 +200,7 @@ class Users::DossiersController < UsersController
end end
def update_params def update_params
params.require(:dossier).permit(:id, :autorisation_donnees, individual_attributes: [:gender, :nom, :prenom, :birthdate]) params.require(:dossier).permit(:id, :autorisation_donnees)
end end
def individual_errors def individual_errors

View file

@ -30,4 +30,11 @@ module ApplicationHelper
root_path root_path
end end
end end
def ensure_safe_json(json)
JSON.parse(json).to_json
rescue Exception => e
Raven.capture_exception(e)
{}
end
end end

View file

@ -5,26 +5,12 @@ class Individual < ApplicationRecord
validates :gender, presence: true, allow_nil: false, on: :update validates :gender, presence: true, allow_nil: false, on: :update
validates :nom, presence: true, allow_blank: false, allow_nil: false, on: :update validates :nom, presence: true, allow_blank: false, allow_nil: false, on: :update
validates :prenom, presence: true, allow_blank: false, allow_nil: false, on: :update validates :prenom, presence: true, allow_blank: false, allow_nil: false, on: :update
validates :birthdate, format: { with: /\A\d{4}\-\d{2}\-\d{2}\z/, message: "La date n'est pas au format AAAA-MM-JJ" }, allow_nil: true
before_validation :set_iso_date, if: -> { birthdate_changed? } def birthdate
before_save :save_birthdate_in_datetime_format second_birthdate
private
def set_iso_date
if birthdate.present? &&
birthdate =~ /\A\d{2}\/\d{2}\/\d{4}\z/
self.birthdate = Date.parse(birthdate).iso8601
end
end end
def save_birthdate_in_datetime_format def birthdate=(date)
if birthdate.present? self.second_birthdate = date
begin
self.second_birthdate = Date.parse(birthdate)
rescue
end
end
end end
end end

View file

@ -20,7 +20,7 @@
.row .row
.col-xs-6.depositaire-label Date de naissance .col-xs-6.depositaire-label Date de naissance
.col-xs-1.comments-off= "-" .col-xs-1.comments-off= "-"
.col-xs-5.depositaire-info= @facade.individual.birthdate .col-xs-4.depositaire-info= @facade.individual.birthdate&.strftime("%d/%m/%Y")
.row.margin-top-20 .row.margin-top-20
- if @facade.champs.present? - if @facade.champs.present?

View file

@ -12,4 +12,4 @@
- if individual.birthdate.present? - if individual.birthdate.present?
%tr %tr
%th.libelle Date de naissance : %th.libelle Date de naissance :
%td= Date.parse(individual.birthdate).strftime("%d/%m/%Y") %td= individual.birthdate&.strftime("%d/%m/%Y")

View file

@ -15,6 +15,6 @@
:javascript :javascript
var getPositionUrl = "#{position_gestionnaire_dossier_path(dossier.procedure, dossier)}"; var getPositionUrl = "#{position_gestionnaire_dossier_path(dossier.procedure, dossier)}";
var dossierJsonLatLngs = #{dossier.json_latlngs}; var dossierJsonLatLngs = #{raw(ensure_safe_json(dossier.json_latlngs))};
var dossierCadastres = #{dossier.cadastres.to_json}; var dossierCadastres = #{raw(ensure_safe_json(dossier.cadastres.to_json))};
var dossierQuartiersPrioritaires = #{dossier.quartier_prioritaires.to_json}; var dossierQuartiersPrioritaires = #{raw(ensure_safe_json(dossier.quartier_prioritaires.to_json))};

View file

@ -0,0 +1,53 @@
namespace :'2018_03_29_inline_entreprise_association' do
task fix_date_fin_exercice: :environment do
Exercice.where(date_fin_exercice: nil).find_each do |exercice|
exercice.update_column(:date_fin_exercice, exercice.dateFinExercice)
end
end
task fix_missing_entreprise: :environment do
Etablissement.includes(:entreprise).where(entreprise_siren: nil).find_each do |etablissement|
dossier_id = etablissement.dossier_id
if !etablissement.entreprise
etablissement.entreprise = Dossier.find_by(id: dossier_id)&.entreprise
end
etablissement.save
end
end
task inline_entreprise_association: :environment do
Etablissement.includes(entreprise: :rna_information, exercices: []).where(entreprise_siren: nil).find_each do |etablissement|
entreprise = etablissement.entreprise
if entreprise
etablissement.entreprise_siren = entreprise.siren
etablissement.entreprise_capital_social = entreprise.capital_social
etablissement.entreprise_numero_tva_intracommunautaire = entreprise.numero_tva_intracommunautaire
etablissement.entreprise_forme_juridique = entreprise.forme_juridique
etablissement.entreprise_forme_juridique_code = entreprise.forme_juridique_code
etablissement.entreprise_nom_commercial = entreprise.nom_commercial
etablissement.entreprise_raison_sociale = entreprise.raison_sociale
etablissement.entreprise_siret_siege_social = entreprise.siret_siege_social
etablissement.entreprise_code_effectif_entreprise = entreprise.code_effectif_entreprise
etablissement.entreprise_date_creation = entreprise.date_creation
etablissement.entreprise_nom = entreprise.nom
etablissement.entreprise_prenom = entreprise.prenom
association = entreprise.rna_information
if association && association.association_id
etablissement.association_rna = association.association_id
etablissement.association_titre = association.titre
etablissement.association_objet = association.objet
etablissement.association_date_creation = association.date_creation
etablissement.association_date_declaration = association.date_declaration
etablissement.association_date_publication = association.date_publication
end
etablissement.save
end
end
end
end

View file

@ -3,6 +3,6 @@ FactoryBot.define do
gender 'M.' gender 'M.'
nom 'Julien' nom 'Julien'
prenom 'Xavier' prenom 'Xavier'
birthdate '1991-11-01' birthdate Date.new(1991, 11, 01)
end end
end end

View file

@ -30,7 +30,7 @@ feature 'As a User I wanna create a dossier' do
expect(page).to have_current_path(modifier_dossier_path(procedure_for_individual.dossiers.last)) expect(page).to have_current_path(modifier_dossier_path(procedure_for_individual.dossiers.last))
expect(user.dossiers.first.individual.birthdate).to eq("1987-10-14") expect(user.dossiers.first.individual.birthdate).to eq(Date.new(1987, 10, 14))
end end
scenario "with a basic text input field for birthdate (type='date' unsupported)" do scenario "with a basic text input field for birthdate (type='date' unsupported)" do
@ -42,7 +42,7 @@ feature 'As a User I wanna create a dossier' do
expect(page).to have_current_path(modifier_dossier_path(procedure_for_individual.dossiers.last)) expect(page).to have_current_path(modifier_dossier_path(procedure_for_individual.dossiers.last))
expect(user.dossiers.first.individual.birthdate).to eq("1987-10-14") expect(user.dossiers.first.individual.birthdate).to eq(Date.new(1987, 10, 14))
end end
end end

View file

@ -17,4 +17,18 @@ describe ApplicationHelper do
it { is_expected.to be_nil } it { is_expected.to be_nil }
end end
end end
describe "#ensure_safe_json" do
subject { ensure_safe_json(json) }
context "with a dirty json" do
let(:json) { "alert('haha');" }
it { is_expected.to eq({}) }
end
context 'with a correct json' do
let(:json) { '[[{"lat": 2.0, "lng": 102.0}, {"lat": 3.0, "lng": 103.0}, {"lat": 2.0, "lng": 102.0}], [{"lat": 2.0, "lng": 102.0}, {"lat": 3.0, "lng": 103.0}, {"lat": 2.0, "lng": 102.0}]]' }
it { is_expected.to eq("[[{\"lat\":2.0,\"lng\":102.0},{\"lat\":3.0,\"lng\":103.0},{\"lat\":2.0,\"lng\":102.0}],[{\"lat\":2.0,\"lng\":102.0},{\"lat\":3.0,\"lng\":103.0},{\"lat\":2.0,\"lng\":102.0}]]") }
end
end
end end

View file

@ -4,7 +4,6 @@ describe Individual do
it { is_expected.to have_db_column(:gender) } it { is_expected.to have_db_column(:gender) }
it { is_expected.to have_db_column(:nom) } it { is_expected.to have_db_column(:nom) }
it { is_expected.to have_db_column(:prenom) } it { is_expected.to have_db_column(:prenom) }
it { is_expected.to have_db_column(:birthdate) }
it { is_expected.to belong_to(:dossier) } it { is_expected.to belong_to(:dossier) }
describe "#save" do describe "#save" do
@ -21,24 +20,21 @@ describe Individual do
context "and the format is dd/mm/yyy " do context "and the format is dd/mm/yyy " do
let(:birthdate_from_user) { "12/11/1980" } let(:birthdate_from_user) { "12/11/1980" }
it { expect(individual.valid?).to be true } it { expect(individual.birthdate).to eq(Date.new(1980, 11, 12)) }
it { expect(individual.birthdate).to eq("1980-11-12") }
it { expect(individual.second_birthdate).to eq(Date.new(1980, 11, 12)) } it { expect(individual.second_birthdate).to eq(Date.new(1980, 11, 12)) }
end end
context "and the format is ISO" do context "and the format is ISO" do
let(:birthdate_from_user) { "1980-11-12" } let(:birthdate_from_user) { "1980-11-12" }
it { expect(individual.valid?).to be true } it { expect(individual.birthdate).to eq(Date.new(1980, 11, 12)) }
it { expect(individual.birthdate).to eq("1980-11-12") }
it { expect(individual.second_birthdate).to eq(Date.new(1980, 11, 12)) } it { expect(individual.second_birthdate).to eq(Date.new(1980, 11, 12)) }
end end
context "and the format is WTF" do context "and the format is WTF" do
let(:birthdate_from_user) { "1980 1 12" } let(:birthdate_from_user) { "1980 1 12" }
it { expect(individual.valid?).to be false } it { expect(individual.birthdate).to be_nil }
it { expect(individual.birthdate).to eq("1980 1 12") }
it { expect(individual.second_birthdate).to be_nil } it { expect(individual.second_birthdate).to be_nil }
end end
end end

View file

@ -0,0 +1,27 @@
require 'spec_helper'
describe 'new_gestionnaire/dossiers/_map.html.haml', type: :view do
subject do
render(partial: 'new_gestionnaire/dossiers/map.html.haml', locals: { dossier: dossier })
end
describe "javascript variables printing" do
let(:dossier) { create(:dossier, :with_entreprise, json_latlngs: json_latlngs) }
context 'with a correct json' do
let(:json_latlngs) { "[[{\"lat\":50.659255436656736,\"lng\":3.080635070800781},{\"lat\":50.659255436656736,\"lng\":3.079690933227539},{\"lat\":50.659962770886516,\"lng\":3.0800342559814453},{\"lat\":50.659962770886516,\"lng\":3.0811500549316406},{\"lat\":50.659255436656736,\"lng\":3.080635070800781}]]" }
before { subject }
it { expect(rendered).to have_content('var dossierJsonLatLngs = [[{"lat":50.659255436656736,"lng":3.080635070800781},{"lat":50.659255436656736,"lng":3.079690933227539},{"lat":50.659962770886516,"lng":3.0800342559814453},{"lat":50.659962770886516,"lng":3.0811500549316406},{"lat":50.659255436656736,"lng":3.080635070800781}]];') }
end
context 'without a correct json' do
let(:json_latlngs) { "dossier" }
before { subject }
it { expect(rendered).to have_content('var dossierJsonLatLngs = {};') }
end
end
end

View file

@ -34,6 +34,6 @@ describe 'new_gestionnaire/dossiers/show.html.haml', type: :view do
it { expect(rendered).to include(individual.gender) } it { expect(rendered).to include(individual.gender) }
it { expect(rendered).to include(individual.nom) } it { expect(rendered).to include(individual.nom) }
it { expect(rendered).to include(individual.prenom) } it { expect(rendered).to include(individual.prenom) }
it { expect(rendered).to include(Date.parse(individual.birthdate).strftime("%d/%m/%Y")) } it { expect(rendered).to include(individual.birthdate.strftime("%d/%m/%Y")) }
end end
end end