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
|
@ -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…
Add table
Add a link
Reference in a new issue