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]
|
||||
|
||||
if checked_autorisation_donnees?
|
||||
begin
|
||||
@facade.dossier.update_attributes!(update_params)
|
||||
rescue
|
||||
flash.now.alert = @facade.dossier.errors.full_messages.join('<br />').html_safe
|
||||
unless Dossier.find(@facade.dossier.id).update_attributes update_params
|
||||
flash.alert = @facade.dossier.errors.full_messages.join('<br />').html_safe
|
||||
|
||||
return redirect_to users_dossier_path(id: @facade.dossier.id)
|
||||
end
|
||||
|
||||
if @facade.dossier.procedure.module_api_carto.use_api_carto
|
||||
redirect_to url_for(controller: :carte, action: :show, dossier_id: @facade.dossier.id)
|
||||
else
|
||||
|
|
|
@ -76,7 +76,9 @@ class Dossier < ActiveRecord::Base
|
|||
end
|
||||
|
||||
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
|
||||
|
||||
def ordered_champs
|
||||
|
|
|
@ -2,9 +2,4 @@ class Individual < ActiveRecord::Base
|
|||
belongs_to :dossier
|
||||
|
||||
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
|
||||
|
|
|
@ -360,12 +360,16 @@ describe Users::DossiersController, type: :controller 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(: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) }
|
||||
|
||||
before do
|
||||
dossier.reload
|
||||
end
|
||||
|
||||
it { expect(dossier.individual.gender).to eq 'Mr' }
|
||||
it { expect(dossier.individual.nom).to eq 'Xavier' }
|
||||
it { expect(dossier.individual.prenom).to eq 'Julien' }
|
||||
it { expect(dossier.individual.nom).to eq 'Julien' }
|
||||
it { expect(dossier.individual.prenom).to eq 'Xavier' }
|
||||
it { expect(dossier.individual.birthdate).to eq '20/01/1991' }
|
||||
it { expect(dossier.procedure.for_individual).to eq true }
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue