From 4276745338cfbd83c6e1968a72df8527cb9d5107 Mon Sep 17 00:00:00 2001 From: Paul Chavard Date: Tue, 26 Jul 2022 11:03:31 +0200 Subject: [PATCH] fix(autosave): morph instead of replace to preserve controller instances --- app/views/champs/piece_justificative/show.turbo_stream.haml | 2 +- spec/controllers/champs/piece_justificative_controller_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/views/champs/piece_justificative/show.turbo_stream.haml b/app/views/champs/piece_justificative/show.turbo_stream.haml index 8263d9cec..0afadc2c1 100644 --- a/app/views/champs/piece_justificative/show.turbo_stream.haml +++ b/app/views/champs/piece_justificative/show.turbo_stream.haml @@ -1,5 +1,5 @@ = fields_for @champ.input_name, @champ do |form| - = turbo_stream.replace @champ.input_group_id, partial: "shared/dossiers/editable_champs/editable_champ", locals: { champ: @champ, form: form } + = turbo_stream.morph @champ.input_group_id, partial: "shared/dossiers/editable_champs/editable_champ", locals: { champ: @champ, form: form } - if @champ.piece_justificative_file.attached? - attachment = @champ.piece_justificative_file.attachment diff --git a/spec/controllers/champs/piece_justificative_controller_spec.rb b/spec/controllers/champs/piece_justificative_controller_spec.rb index 6e6facb88..d806ad19f 100644 --- a/spec/controllers/champs/piece_justificative_controller_spec.rb +++ b/spec/controllers/champs/piece_justificative_controller_spec.rb @@ -29,7 +29,7 @@ describe Champs::PieceJustificativeController, type: :controller do it 'renders the attachment template as Javascript' do subject expect(response.status).to eq(200) - expect(response.body).to include("action=\"replace\" target=\"#{champ.input_group_id}\"") + expect(response.body).to include(""action":"morph","target":"#{champ.input_group_id}"") end it 'updates dossier.last_champ_updated_at' do