diff --git a/app/controllers/administrateurs/groupe_instructeurs_controller.rb b/app/controllers/administrateurs/groupe_instructeurs_controller.rb index db171b450..58d1cb379 100644 --- a/app/controllers/administrateurs/groupe_instructeurs_controller.rb +++ b/app/controllers/administrateurs/groupe_instructeurs_controller.rb @@ -215,7 +215,7 @@ module Administrateurs else file = group_csv_file.read base_encoding = CharlockHolmes::EncodingDetector.detect(file) - groupes_emails = ACSV::CSV.new(file.encode("UTF-8", base_encoding[:encoding], invalid: :replace, replace: ""), headers: true, header_converters: :downcase) + groupes_emails = ACSV::CSV.new_for_ruby3(file.encode("UTF-8", base_encoding[:encoding], invalid: :replace, replace: ""), headers: true, header_converters: :downcase) .map { |r| r.to_h.slice('groupe', 'email') } groupes_emails_has_keys = groupes_emails.first.has_key?("groupe") && groupes_emails.first.has_key?("email") diff --git a/config/initializers/acsv.rb b/config/initializers/acsv.rb new file mode 100644 index 000000000..3a24d2032 --- /dev/null +++ b/config/initializers/acsv.rb @@ -0,0 +1,16 @@ +require 'csv' + +# PR : https://github.com/wvengen/ruby-acsv/pull/3 +module ACSV + class CSV < ::CSV + def self.new_for_ruby3(data, options = {}) + options[:col_sep] ||= ACSV::Detect.separator(data) + # 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 + # super(data, options) + # we do + ::CSV.new(data, **options) + end + end +end