ProcedureRevision#compare_type_de_champ: fix bug comparaison character_limit chaine vide vs nil

This commit is contained in:
benoitqueyron 2024-08-28 10:31:26 +02:00
parent 3c5749e45a
commit 4f62590b7a
No known key found for this signature in database
GPG key ID: AD3C38C9ACA84135
2 changed files with 24 additions and 1 deletions

View file

@ -440,7 +440,7 @@ class ProcedureRevision < ApplicationRecord
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,

View file

@ -537,6 +537,29 @@ describe ProcedureRevision do
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 }