update dossier after saving champ
update last_champ_updated_at without hook update last_champ_private_updated_at without hook Co-authored-by: Christophe Robillard <christophe.robillard@beta.gouv.fr>
This commit is contained in:
parent
b940d2e1b0
commit
c772c3454c
4 changed files with 74 additions and 16 deletions
|
@ -192,7 +192,11 @@ module Instructeurs
|
|||
|
||||
def update_annotations
|
||||
dossier = current_instructeur.dossiers.includes(champs_private: :type_de_champ).find(params[:dossier_id])
|
||||
dossier.update(champs_private_params)
|
||||
dossier.assign_attributes(champs_private_params)
|
||||
if dossier.champs_private.any?(&:changed?)
|
||||
dossier.last_champ_private_updated_at = Time.zone.now
|
||||
end
|
||||
dossier.save
|
||||
dossier.modifier_annotations!(current_instructeur)
|
||||
redirect_to annotations_privees_instructeur_dossier_path(procedure, dossier)
|
||||
end
|
||||
|
|
|
@ -345,7 +345,11 @@ module Users
|
|||
errors = []
|
||||
|
||||
if champs_params[:dossier]
|
||||
if !@dossier.update(champs_params[:dossier])
|
||||
@dossier.assign_attributes(champs_params[:dossier])
|
||||
if @dossier.champs.any?(&:changed?)
|
||||
@dossier.last_champ_updated_at = Time.zone.now
|
||||
end
|
||||
if !@dossier.save
|
||||
errors += @dossier.errors.full_messages
|
||||
elsif change_groupe_instructeur?
|
||||
groupe_instructeur = @dossier.procedure.groupe_instructeurs.find(params[:dossier][:groupe_instructeur_id])
|
||||
|
|
|
@ -584,9 +584,26 @@ describe Instructeurs::DossiersController, type: :controller do
|
|||
create(:dossier, :en_construction, procedure: procedure, champs_private: [champ_multiple_drop_down_list, champ_linked_drop_down_list, champ_datetime, champ_repetition])
|
||||
end
|
||||
|
||||
let(:now) { Time.zone.parse('01/01/2100') }
|
||||
|
||||
before do
|
||||
patch :update_annotations, params: {
|
||||
procedure_id: procedure.id,
|
||||
Timecop.freeze(now)
|
||||
patch :update_annotations, params: params
|
||||
|
||||
champ_multiple_drop_down_list.reload
|
||||
champ_linked_drop_down_list.reload
|
||||
champ_datetime.reload
|
||||
champ_repetition.reload
|
||||
end
|
||||
|
||||
after do
|
||||
Timecop.return
|
||||
end
|
||||
|
||||
context "with new values for champs_private" do
|
||||
let(:params) do
|
||||
{
|
||||
procedure_id: procedure.id,
|
||||
dossier_id: dossier.id,
|
||||
dossier: {
|
||||
champs_private_attributes: {
|
||||
|
@ -616,20 +633,36 @@ describe Instructeurs::DossiersController, type: :controller do
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
champ_multiple_drop_down_list.reload
|
||||
champ_linked_drop_down_list.reload
|
||||
champ_datetime.reload
|
||||
champ_repetition.reload
|
||||
}
|
||||
end
|
||||
it { expect(champ_multiple_drop_down_list.value).to eq('["un", "deux"]') }
|
||||
it { expect(champ_linked_drop_down_list.primary_value).to eq('primary') }
|
||||
it { expect(champ_linked_drop_down_list.secondary_value).to eq('secondary') }
|
||||
it { expect(champ_datetime.value).to eq('21/12/2019 13:17') }
|
||||
it { expect(champ_repetition.champs.first.value).to eq('text') }
|
||||
it { expect(dossier.reload.last_champ_private_updated_at).to eq(now) }
|
||||
it { expect(response).to redirect_to(annotations_privees_instructeur_dossier_path(dossier.procedure, dossier)) }
|
||||
end
|
||||
|
||||
it { expect(champ_multiple_drop_down_list.value).to eq('["un", "deux"]') }
|
||||
it { expect(champ_linked_drop_down_list.primary_value).to eq('primary') }
|
||||
it { expect(champ_linked_drop_down_list.secondary_value).to eq('secondary') }
|
||||
it { expect(champ_datetime.value).to eq('21/12/2019 13:17') }
|
||||
it { expect(champ_repetition.champs.first.value).to eq('text') }
|
||||
it { expect(response).to redirect_to(annotations_privees_instructeur_dossier_path(dossier.procedure, dossier)) }
|
||||
context "without new values for champs_private" do
|
||||
let(:params) do
|
||||
{
|
||||
procedure_id: procedure.id,
|
||||
dossier_id: dossier.id,
|
||||
dossier: {
|
||||
champs_private_attributes: {},
|
||||
champs_attributes: {
|
||||
'0': {
|
||||
id: champ_multiple_drop_down_list.id,
|
||||
value: ['', 'un', 'deux']
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
it { expect(dossier.reload.last_champ_private_updated_at).to eq(nil) }
|
||||
it { expect(response).to redirect_to(annotations_privees_instructeur_dossier_path(dossier.procedure, dossier)) }
|
||||
end
|
||||
end
|
||||
|
||||
describe "#telecharger_pjs" do
|
||||
|
|
|
@ -378,6 +378,22 @@ describe Users::DossiersController, type: :controller do
|
|||
expect(dossier.reload.state).to eq(Dossier.states.fetch(:en_construction))
|
||||
end
|
||||
|
||||
context 'without new values for champs' do
|
||||
let(:submit_payload) do
|
||||
{
|
||||
id: dossier.id,
|
||||
dossier: {
|
||||
champs_attributes: {}
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
it "doesn't set last_champ_updated_at" do
|
||||
subject
|
||||
expect(dossier.reload.last_champ_updated_at).to eq(nil)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with instructeurs ok to be notified instantly' do
|
||||
let!(:instructeur_with_instant_email_dossier) { create(:instructeur) }
|
||||
let!(:instructeur_without_instant_email_dossier) { create(:instructeur) }
|
||||
|
@ -576,6 +592,7 @@ describe Users::DossiersController, type: :controller do
|
|||
it 'updates the champs' do
|
||||
subject
|
||||
expect(first_champ.reload.value).to eq('beautiful value')
|
||||
expect(first_champ.dossier.reload.last_champ_updated_at).to eq(now)
|
||||
expect(piece_justificative_champ.reload.piece_justificative_file).to be_attached
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue