Fix bug who does not saved Individual information
This commit is contained in:
parent
c985cee441
commit
78bba67995
4 changed files with 14 additions and 13 deletions
|
@ -115,12 +115,12 @@ class Users::DossiersController < UsersController
|
||||||
@facade = facade params[:dossier][:id]
|
@facade = facade params[:dossier][:id]
|
||||||
|
|
||||||
if checked_autorisation_donnees?
|
if checked_autorisation_donnees?
|
||||||
begin
|
unless Dossier.find(@facade.dossier.id).update_attributes update_params
|
||||||
@facade.dossier.update_attributes!(update_params)
|
flash.alert = @facade.dossier.errors.full_messages.join('<br />').html_safe
|
||||||
rescue
|
|
||||||
flash.now.alert = @facade.dossier.errors.full_messages.join('<br />').html_safe
|
|
||||||
return redirect_to users_dossier_path(id: @facade.dossier.id)
|
return redirect_to users_dossier_path(id: @facade.dossier.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
if @facade.dossier.procedure.module_api_carto.use_api_carto
|
if @facade.dossier.procedure.module_api_carto.use_api_carto
|
||||||
redirect_to url_for(controller: :carte, action: :show, dossier_id: @facade.dossier.id)
|
redirect_to url_for(controller: :carte, action: :show, dossier_id: @facade.dossier.id)
|
||||||
else
|
else
|
||||||
|
|
|
@ -76,7 +76,9 @@ class Dossier < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def build_default_individual
|
def build_default_individual
|
||||||
Individual.new(dossier_id: id).save(validate: false)
|
if Individual.where(dossier_id: self.id).count == 0
|
||||||
|
Individual.create(dossier: self)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def ordered_champs
|
def ordered_champs
|
||||||
|
|
|
@ -2,9 +2,4 @@ class Individual < ActiveRecord::Base
|
||||||
belongs_to :dossier
|
belongs_to :dossier
|
||||||
|
|
||||||
validates_uniqueness_of :dossier_id
|
validates_uniqueness_of :dossier_id
|
||||||
|
|
||||||
validates :gender, presence: true, allow_nil: false, allow_blank: false
|
|
||||||
validates :nom, presence: true, allow_nil: false, allow_blank: false
|
|
||||||
validates :prenom, presence: true, allow_nil: false, allow_blank: false
|
|
||||||
validates :birthdate, presence: true, allow_nil: false, allow_blank: false
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -360,12 +360,16 @@ describe Users::DossiersController, type: :controller do
|
||||||
|
|
||||||
context 'when procedure is for individual' do
|
context 'when procedure is for individual' do
|
||||||
let(:params) { {id: dossier_id, dossier: {id: dossier_id, autorisation_donnees: '1', individual_attributes: individual_params}} }
|
let(:params) { {id: dossier_id, dossier: {id: dossier_id, autorisation_donnees: '1', individual_attributes: individual_params}} }
|
||||||
let(:individual_params) { {id: dossier.individual.id, gender: 'Mr', nom: 'Julien', prenom: 'Xavier', birthdate: '20/01/1991', dossier_id: dossier.id} }
|
let(:individual_params) { {gender: 'Mr', nom: 'Julien', prenom: 'Xavier', birthdate: '20/01/1991'} }
|
||||||
let(:procedure) { create(:procedure, :published, for_individual: true) }
|
let(:procedure) { create(:procedure, :published, for_individual: true) }
|
||||||
|
|
||||||
|
before do
|
||||||
|
dossier.reload
|
||||||
|
end
|
||||||
|
|
||||||
it { expect(dossier.individual.gender).to eq 'Mr' }
|
it { expect(dossier.individual.gender).to eq 'Mr' }
|
||||||
it { expect(dossier.individual.nom).to eq 'Xavier' }
|
it { expect(dossier.individual.nom).to eq 'Julien' }
|
||||||
it { expect(dossier.individual.prenom).to eq 'Julien' }
|
it { expect(dossier.individual.prenom).to eq 'Xavier' }
|
||||||
it { expect(dossier.individual.birthdate).to eq '20/01/1991' }
|
it { expect(dossier.individual.birthdate).to eq '20/01/1991' }
|
||||||
it { expect(dossier.procedure.for_individual).to eq true }
|
it { expect(dossier.procedure.for_individual).to eq true }
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue