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
|
def libelle_for_export
|
||||||
str = "(#{stable_id}) #{libelle}"
|
str = "(#{stable_id}) #{libelle}"
|
||||||
# /\*?[] are invalid Excel worksheet characters
|
# /\*?[] are invalid Excel worksheet characters
|
||||||
ActiveStorage::Filename.new(str.delete('[]*?')).sanitized.truncate(30)
|
ActiveStorage::Filename.new(str.delete('[]*?')).sanitized
|
||||||
end
|
end
|
||||||
|
|
||||||
class Row < Hashie::Dash
|
class Row < Hashie::Dash
|
||||||
|
|
|
@ -62,7 +62,7 @@ class ProcedureExportService
|
||||||
}
|
}
|
||||||
|
|
||||||
def options_for(table, format)
|
def options_for(table, format)
|
||||||
case table
|
options = case table
|
||||||
when :dossiers
|
when :dossiers
|
||||||
{ instances: dossiers.to_a, sheet_name: 'Dossiers', spreadsheet_columns: :"spreadsheet_columns_#{format}" }
|
{ instances: dossiers.to_a, sheet_name: 'Dossiers', spreadsheet_columns: :"spreadsheet_columns_#{format}" }
|
||||||
when :etablissements
|
when :etablissements
|
||||||
|
@ -72,5 +72,8 @@ class ProcedureExportService
|
||||||
when Array
|
when Array
|
||||||
{ instances: table.last, sheet_name: table.first }
|
{ instances: table.last, sheet_name: table.first }
|
||||||
end.merge(DEFAULT_STYLES)
|
end.merge(DEFAULT_STYLES)
|
||||||
|
|
||||||
|
options[:sheet_name] = options[:sheet_name].truncate(30)
|
||||||
|
options
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -356,6 +356,21 @@ describe ProcedureExportService do
|
||||||
end
|
end
|
||||||
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
|
context 'with non unique labels' do
|
||||||
let(:dossier) { create(:dossier, :en_instruction, :with_all_champs, :with_individual, procedure: procedure) }
|
let(:dossier) { create(:dossier, :en_instruction, :with_all_champs, :with_individual, procedure: procedure) }
|
||||||
let(:champ_repetition) { dossier.champs.find { |champ| champ.type_champ == 'repetition' } }
|
let(:champ_repetition) { dossier.champs.find { |champ| champ.type_champ == 'repetition' } }
|
||||||
|
|
Loading…
Add table
Reference in a new issue