From 4f62590b7a28b42069cca1892651532defe752ea Mon Sep 17 00:00:00 2001 From: benoitqueyron <72251526+Benoit-MINT@users.noreply.github.com> Date: Wed, 28 Aug 2024 10:31:26 +0200 Subject: [PATCH] ProcedureRevision#compare_type_de_champ: fix bug comparaison character_limit chaine vide vs nil --- app/models/procedure_revision.rb | 2 +- spec/models/procedure_revision_spec.rb | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/app/models/procedure_revision.rb b/app/models/procedure_revision.rb index 0c8c8dc27ff..6a0631eb937 100644 --- a/app/models/procedure_revision.rb +++ b/app/models/procedure_revision.rb @@ -440,7 +440,7 @@ def compare_type_de_champ(from_type_de_champ, to_type_de_champ, from_coordinates to_type_de_champ.filename_for_attachement(:notice_explicative)) end elsif to_type_de_champ.textarea? - if from_type_de_champ.character_limit != to_type_de_champ.character_limit + if from_type_de_champ.character_limit.presence != to_type_de_champ.character_limit.presence changes << ProcedureRevisionChange::UpdateChamp.new(from_type_de_champ, :character_limit, from_type_de_champ.character_limit, diff --git a/spec/models/procedure_revision_spec.rb b/spec/models/procedure_revision_spec.rb index 592187aaae4..97e53841f85 100644 --- a/spec/models/procedure_revision_spec.rb +++ b/spec/models/procedure_revision_spec.rb @@ -537,6 +537,29 @@ end end + context 'when a type de champ is transformed into a text_area with no character limit' do + let(:procedure) { create(:procedure, types_de_champ_public: [{ type: :text }]) } + + before do + updated_tdc = new_draft.find_and_ensure_exclusive_use(first_tdc.stable_id) + updated_tdc.update(type_champ: :textarea, options: { "character_limit" => "" }) + end + + it do + is_expected.to eq([ + { + op: :update, + attribute: :type_champ, + label: first_tdc.libelle, + private: false, + from: "text", + to: "textarea", + stable_id: first_tdc.stable_id + } + ]) + end + end + context 'when a type de champ is moved' do let(:procedure) { create(:procedure, types_de_champ_public: Array.new(3) { { type: :text } }) } let(:new_draft_second_tdc) { new_draft.types_de_champ_public.second }