Merge pull request #5614 from Keirua/fix-length-error-worksheet-names
Length sanitization for worksheet exports
This commit is contained in:
commit
77fd783fa9
3 changed files with 20 additions and 2 deletions
|
@ -53,7 +53,7 @@ class Champs::RepetitionChamp < Champ
|
|||
def libelle_for_export
|
||||
str = "(#{stable_id}) #{libelle}"
|
||||
# /\*?[] are invalid Excel worksheet characters
|
||||
ActiveStorage::Filename.new(str.delete('[]*?')).sanitized.truncate(30)
|
||||
ActiveStorage::Filename.new(str.delete('[]*?')).sanitized
|
||||
end
|
||||
|
||||
class Row < Hashie::Dash
|
||||
|
|
|
@ -62,7 +62,7 @@ class ProcedureExportService
|
|||
}
|
||||
|
||||
def options_for(table, format)
|
||||
case table
|
||||
options = case table
|
||||
when :dossiers
|
||||
{ instances: dossiers.to_a, sheet_name: 'Dossiers', spreadsheet_columns: :"spreadsheet_columns_#{format}" }
|
||||
when :etablissements
|
||||
|
@ -72,5 +72,8 @@ class ProcedureExportService
|
|||
when Array
|
||||
{ instances: table.last, sheet_name: table.first }
|
||||
end.merge(DEFAULT_STYLES)
|
||||
|
||||
options[:sheet_name] = options[:sheet_name].truncate(30)
|
||||
options
|
||||
end
|
||||
end
|
||||
|
|
|
@ -356,6 +356,21 @@ describe ProcedureExportService do
|
|||
end
|
||||
end
|
||||
|
||||
context 'with long libelle' do
|
||||
before do
|
||||
procedure.types_de_champ.each do |c|
|
||||
c.update!(libelle: "#{c.id} - Quam rem nam maiores numquam dolorem nesciunt. Cum et possimus et aut. Fugit voluptas qui qui.")
|
||||
end
|
||||
champ_repetition.champs.each do |c|
|
||||
c.type_de_champ.update!(libelle: "#{c.id} - Quam rem nam maiores numquam dolorem nesciunt. Cum et possimus et aut. Fugit voluptas qui qui.")
|
||||
end
|
||||
end
|
||||
|
||||
it 'should have valid sheet name' do
|
||||
expect { subject }.not_to raise_error(ArgumentError)
|
||||
end
|
||||
end
|
||||
|
||||
context 'with non unique labels' do
|
||||
let(:dossier) { create(:dossier, :en_instruction, :with_all_champs, :with_individual, procedure: procedure) }
|
||||
let(:champ_repetition) { dossier.champs.find { |champ| champ.type_champ == 'repetition' } }
|
||||
|
|
Loading…
Reference in a new issue