[Fix #1409] Identite can be updated
This commit is contained in:
parent
d9265d9686
commit
9627ba43c0
9 changed files with 90 additions and 1 deletions
|
@ -11,6 +11,26 @@ module NewUser
|
|||
@user = current_user
|
||||
end
|
||||
|
||||
def update_identite
|
||||
@dossier = dossier
|
||||
|
||||
individual_updated = @dossier.individual.update(individual_params)
|
||||
dossier_updated = @dossier.update(dossier_params)
|
||||
|
||||
if individual_updated && dossier_updated
|
||||
flash.notice = "Identité enregistrée"
|
||||
|
||||
if @dossier.procedure.module_api_carto.use_api_carto
|
||||
redirect_to users_dossier_carte_path(@dossier.id)
|
||||
else
|
||||
redirect_to identite_dossier_path(@dossier) # Simon should replace this with dossier_path when done
|
||||
end
|
||||
else
|
||||
flash.now.alert = @dossier.errors.full_messages
|
||||
render :identite
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def dossier
|
||||
|
@ -23,5 +43,13 @@ module NewUser
|
|||
redirect_to root_path
|
||||
end
|
||||
end
|
||||
|
||||
def individual_params
|
||||
params.require(:individual).permit(:gender, :nom, :prenom, :birthdate)
|
||||
end
|
||||
|
||||
def dossier_params
|
||||
params.require(:dossier).permit(:autorisation_donnees)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -37,6 +37,8 @@ class Dossier < ActiveRecord::Base
|
|||
accepts_nested_attributes_for :champs
|
||||
accepts_nested_attributes_for :champs_private
|
||||
|
||||
validates :autorisation_donnees, acceptance: { message: 'doit être coché' }, allow_nil: false, on: :update
|
||||
|
||||
default_scope { where(hidden_at: nil) }
|
||||
scope :state_brouillon, -> { where(state: 'brouillon') }
|
||||
scope :state_not_brouillon, -> { where.not(state: 'brouillon') }
|
||||
|
@ -177,7 +179,7 @@ class Dossier < ActiveRecord::Base
|
|||
etablissement.destroy
|
||||
entreprise.destroy
|
||||
|
||||
update_attributes(autorisation_donnees: false)
|
||||
update_columns(autorisation_donnees: false)
|
||||
end
|
||||
|
||||
def total_follow
|
||||
|
|
|
@ -2,5 +2,18 @@ class Individual < ActiveRecord::Base
|
|||
belongs_to :dossier
|
||||
|
||||
validates_uniqueness_of :dossier_id
|
||||
validates :gender, presence: true, 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 :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? }
|
||||
|
||||
private
|
||||
|
||||
def set_iso_date
|
||||
if birthdate.present?
|
||||
self.birthdate = Date.parse(birthdate).iso8601
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -14,6 +14,7 @@ fr:
|
|||
accepte: "Accepté"
|
||||
refuse: "Refusé"
|
||||
sans_suite: "Sans suite"
|
||||
autorisation_donnees: Acceptation des CGU
|
||||
|
||||
errors:
|
||||
models:
|
||||
|
|
|
@ -10,6 +10,8 @@ fr:
|
|||
models:
|
||||
individual:
|
||||
attributes:
|
||||
gender:
|
||||
blank: 'doit être rempli'
|
||||
nom:
|
||||
blank: 'doit être rempli'
|
||||
prenom:
|
||||
|
|
|
@ -204,6 +204,7 @@ Rails.application.routes.draw do
|
|||
resources :dossiers, only: [] do
|
||||
member do
|
||||
get 'identite'
|
||||
patch 'update_identite'
|
||||
end
|
||||
get 'attestation'
|
||||
end
|
||||
|
|
|
@ -64,4 +64,43 @@ describe NewUser::DossiersController, type: :controller do
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'update_identite' do
|
||||
let(:procedure) { create(:procedure, :for_individual) }
|
||||
let(:dossier) { create(:dossier, user: user, procedure: procedure) }
|
||||
|
||||
subject { post :update_identite, params: { id: dossier.id, individual: individual_params, dossier: dossier_params } }
|
||||
|
||||
before do
|
||||
sign_in(user)
|
||||
subject
|
||||
end
|
||||
|
||||
context 'with correct individual and dossier params' do
|
||||
let(:individual_params) { { gender: 'M', nom: 'Mouse', prenom: 'Mickey' } }
|
||||
let(:dossier_params) { { autorisation_donnees: true } }
|
||||
|
||||
it do
|
||||
expect(response).to redirect_to(users_dossier_description_path(dossier))
|
||||
end
|
||||
|
||||
context 'on a procedure with carto' do
|
||||
let(:procedure) { create(:procedure, :for_individual, :with_api_carto) }
|
||||
|
||||
it do
|
||||
expect(response).to redirect_to(users_dossier_carte_path(dossier))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with incorrect individual and dossier params' do
|
||||
let(:individual_params) { { gender: '', nom: '', prenom: '' } }
|
||||
let(:dossier_params) { { autorisation_donnees: nil } }
|
||||
|
||||
it do
|
||||
expect(response).not_to have_http_status(:redirect)
|
||||
expect(flash[:alert]).to include("Civilité doit être rempli", "Nom doit être rempli", "Prénom doit être rempli", "Acceptation des CGU doit être coché")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -365,6 +365,8 @@ describe Users::DossiersController, type: :controller do
|
|||
|
||||
before do
|
||||
sign_in dossier.user
|
||||
dossier.update_columns(autorisation_donnees: nil)
|
||||
dossier.reload
|
||||
subject
|
||||
end
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
FactoryBot.define do
|
||||
factory :dossier do
|
||||
autorisation_donnees true
|
||||
state 'brouillon'
|
||||
association :user, factory: [:user]
|
||||
|
||||
|
|
Loading…
Reference in a new issue