fix(groupe_instructeurs): can parse a monocolumn csv file

This commit is contained in:
Eric Leroy-Terquem 2023-01-18 16:38:56 +01:00
parent e87bb24872
commit 3aa7793ed3
2 changed files with 12 additions and 1 deletions

View file

@ -4,7 +4,7 @@ require 'csv'
module ACSV
class CSV < ::CSV
def self.new_for_ruby3(data, options = {})
options[:col_sep] ||= ACSV::Detect.separator(data)
options[:col_sep] ||= ACSV::Detect.separator(data) || :auto
# because of the Separation of positional and keyword arguments in Ruby 3.0
# (https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/)
# instead of

View file

@ -405,6 +405,17 @@ describe Administrateurs::GroupeInstructeursController, type: :controller do
it { expect(flash.alert).to eq("Import terminé. Cependant les emails suivants ne sont pas pris en compte: kara") }
end
context 'when the csv file has only one column' do
let(:csv_file) { fixture_file_upload('spec/fixtures/files/valid-instructeurs-file.csv', 'text/csv') }
before { subject }
it { expect { subject }.not_to raise_error }
it { expect(response.status).to eq(302) }
it { expect(flash.alert).to be_present }
it { expect(flash.alert).to eq("Importation impossible, veuillez importer un csv <a href=\"/csv/#{I18n.locale}/import-groupe-test.csv\">suivant ce modèle</a>") }
end
context 'when the file content type is application/vnd.ms-excel' do
let(:csv_file) { fixture_file_upload('spec/fixtures/files/groupe_avec_caracteres_speciaux.csv', "application/vnd.ms-excel") }