tdc: add libelle_as_filename
This commit is contained in:
parent
190addd317
commit
53a48f963d
2 changed files with 14 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue