tdc: add libelle_as_filename

This commit is contained in:
simon lehericey 2024-07-22 17:01:32 +02:00
parent 190addd317
commit 53a48f963d
No known key found for this signature in database
GPG key ID: CDE670D827C7B3C5
2 changed files with 14 additions and 0 deletions

View file

@ -676,6 +676,12 @@ class TypeDeChamp < ApplicationRecord
end
end
def libelle_as_filename
libelle.gsub(/[[:space:]]+/, ' ')
.truncate(30, omission: '', separator: ' ')
.parameterize
end
class << self
def champ_value(type_champ, champ)
dynamic_type_class = type_champ_to_class_name(type_champ).constantize

View file

@ -302,4 +302,12 @@ describe TypeDeChamp do
it { expect(create(:type_de_champ, :header_section, libelle: " 2.3 Test").libelle).to eq("2.3 Test") }
it { expect(create(:type_de_champ, libelle: " fix me ").libelle).to eq("fix me") }
end
describe '#safe_filename' do
subject { build(:type_de_champ, libelle:).libelle_as_filename }
let(:libelle) { " #/🐉 1 très intéressant Bilan " }
it { is_expected.to eq("1-tres-interessant-bilan") }
end
end