diff --git a/app/models/exported_column.rb b/app/models/exported_column.rb index dfedf20b3..651407a71 100644 --- a/app/models/exported_column.rb +++ b/app/models/exported_column.rb @@ -14,15 +14,12 @@ class ExportedColumn [libelle, ExportedColumnFormatter.format(column:, champ_or_dossier:, format:), spreadsheet_architect_type] end - # see: https://github.com/westonganger/spreadsheet_architect/blob/771e2e5558fbf6e0cb830e881a7214fa710e49c3/lib/spreadsheet_architect.rb#L39 def spreadsheet_architect_type case @column.type when :boolean :boolean - when :decimal + when :decimal, :integer :float - when :number - :integer when :datetime :time when :date diff --git a/spec/services/procedure_export_service_tabular_spec.rb b/spec/services/procedure_export_service_tabular_spec.rb index b2eb2367d..0a20341f7 100644 --- a/spec/services/procedure_export_service_tabular_spec.rb +++ b/spec/services/procedure_export_service_tabular_spec.rb @@ -6,7 +6,6 @@ describe ProcedureExportService do let(:instructeur) { create(: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(:export_template) { create(:export_template, kind:, exported_columns:, groupe_instructeur: procedure.defaut_groupe_instructeur) } let(:for_individual) { true } let(:types_de_champ_public) do [ @@ -25,18 +24,19 @@ describe ProcedureExportService do let(:exported_columns) { [] } 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 service .to_xlsx .open { |f| SimpleXlsxReader.open(f.path) } 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 it 'should have a sheet for each record type' do expect(subject.sheets.map(&:name)).to eq(['Dossiers', 'Etablissements', 'Avis']) @@ -106,6 +106,33 @@ describe ProcedureExportService do before { create(:dossier, :with_populated_champs, procedure:) } it { expect(dossiers_sheet.data.last.last).to eq "val1, val2" } 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 describe 'Etablissement sheet' do