feat(export.numbers): cast to float, otherwise it is implicitly casted

as string
This commit is contained in:
mfo 2024-11-14 09:12:25 +01:00
parent db053d36c9
commit 1fccf0fd18
No known key found for this signature in database
GPG key ID: 7CE3E1F5B794A8EC
2 changed files with 35 additions and 11 deletions

View file

@ -14,15 +14,12 @@ class ExportedColumn
[libelle, ExportedColumnFormatter.format(column:, champ_or_dossier:, format:), spreadsheet_architect_type] [libelle, ExportedColumnFormatter.format(column:, champ_or_dossier:, format:), spreadsheet_architect_type]
end end
# see: https://github.com/westonganger/spreadsheet_architect/blob/771e2e5558fbf6e0cb830e881a7214fa710e49c3/lib/spreadsheet_architect.rb#L39
def spreadsheet_architect_type def spreadsheet_architect_type
case @column.type case @column.type
when :boolean when :boolean
:boolean :boolean
when :decimal when :decimal, :integer
:float :float
when :number
:integer
when :datetime when :datetime
:time :time
when :date when :date

View file

@ -6,7 +6,6 @@ describe ProcedureExportService do
let(:instructeur) { create(:instructeur) } let(:instructeur) { create(:instructeur) }
let(:procedure) { create(:procedure, types_de_champ_public:, for_individual:, ask_birthday: true, instructeurs: [instructeur]) } let(:procedure) { create(:procedure, types_de_champ_public:, for_individual:, ask_birthday: true, instructeurs: [instructeur]) }
let(:service) { ProcedureExportService.new(procedure, procedure.dossiers, instructeur, export_template) } let(:service) { ProcedureExportService.new(procedure, procedure.dossiers, instructeur, export_template) }
let(:export_template) { create(:export_template, kind:, exported_columns:, groupe_instructeur: procedure.defaut_groupe_instructeur) }
let(:for_individual) { true } let(:for_individual) { true }
let(:types_de_champ_public) do let(:types_de_champ_public) do
[ [
@ -25,18 +24,19 @@ describe ProcedureExportService do
let(:exported_columns) { [] } let(:exported_columns) { [] }
describe 'to_xlsx' do describe 'to_xlsx' do
let(:kind) { 'xlsx' }
let(:export_template) { create(:export_template, kind:, exported_columns:, groupe_instructeur: procedure.defaut_groupe_instructeur) }
let(:dossiers_sheet) { subject.sheets.first }
let(:etablissements_sheet) { subject.sheets.second }
let(:avis_sheet) { subject.sheets.third }
let(:repetition_sheet) { subject.sheets.fourth }
subject do subject do
service service
.to_xlsx .to_xlsx
.open { |f| SimpleXlsxReader.open(f.path) } .open { |f| SimpleXlsxReader.open(f.path) }
end end
let(:kind) { 'xlsx' }
let(:dossiers_sheet) { subject.sheets.first }
let(:etablissements_sheet) { subject.sheets.second }
let(:avis_sheet) { subject.sheets.third }
let(:repetition_sheet) { subject.sheets.fourth }
describe 'sheets' do describe 'sheets' do
it 'should have a sheet for each record type' do it 'should have a sheet for each record type' do
expect(subject.sheets.map(&:name)).to eq(['Dossiers', 'Etablissements', 'Avis']) expect(subject.sheets.map(&:name)).to eq(['Dossiers', 'Etablissements', 'Avis'])
@ -106,6 +106,33 @@ describe ProcedureExportService do
before { create(:dossier, :with_populated_champs, procedure:) } before { create(:dossier, :with_populated_champs, procedure:) }
it { expect(dossiers_sheet.data.last.last).to eq "val1, val2" } it { expect(dossiers_sheet.data.last.last).to eq "val1, val2" }
end end
context 'with a dossier TypeDeChamp:YesNo' do
let(:types_de_champ_public) { [{ type: :yes_no, libelle: "yes_no", mandatory: true }] }
let(:exported_columns) { [ExportedColumn.new(libelle: 'yes_no', column: procedure.find_column(label: 'yes_no'))] }
before { create(:dossier, :with_populated_champs, procedure:) }
it { expect(dossiers_sheet.data.last.last).to eq true }
end
context 'with a dossier TypeDeChamp:Checkbox' do
let(:types_de_champ_public) { [{ type: :checkbox, libelle: "checkbox", mandatory: true }] }
let(:exported_columns) { [ExportedColumn.new(libelle: 'checkbox', column: procedure.find_column(label: 'checkbox'))] }
before { create(:dossier, :with_populated_champs, procedure:) }
it { expect(dossiers_sheet.data.last.last).to eq true }
end
context 'with a dossier TypeDeChamp:DecimalNumber' do
let(:types_de_champ_public) { [{ type: :decimal_number, libelle: "decimal", mandatory: true }] }
let(:exported_columns) { [ExportedColumn.new(libelle: 'decimal', column: procedure.find_column(label: 'decimal'))] }
before { create(:dossier, :with_populated_champs, procedure:) }
it { expect(dossiers_sheet.data.last.last).to eq 42.1 }
end
context 'with a dossier TypeDeChamp:IntegerNumber' do
let(:types_de_champ_public) { [{ type: :integer_number, libelle: "integer", mandatory: true }] }
let(:exported_columns) { [ExportedColumn.new(libelle: 'integer', column: procedure.find_column(label: 'integer'))] }
before { create(:dossier, :with_populated_champs, procedure:) }
it { expect(dossiers_sheet.data.last.last).to eq 42.0 }
end
end end
describe 'Etablissement sheet' do describe 'Etablissement sheet' do