Skip to content

Commit

Permalink
🐛 Corrige l'import XLS pour les questions
Browse files Browse the repository at this point in the history
  • Loading branch information
cprodhomme committed Feb 10, 2025
1 parent c9c2f6e commit e0d0d87
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
22 changes: 15 additions & 7 deletions app/admin/questions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@

controller do
def import_xls
return if params[:file_xls].blank?
return invalide_format_xls unless ImportExport::ImportXls.fichier_xls?(params[:file_xls])
return if fichier_import.blank?
return invalide_format_xls unless ImportExport::ImportXls.fichier_xls?(fichier_import)

initialise_import
flash[:success] = I18n.t('.layouts.succes.import_question')
Expand All @@ -29,14 +29,22 @@ def import_xls

private

def fichier_import
params[:question][:file_xls]
end

def type_question
params[:question][:type]
end

def initialise_import
ImportExport::Questions::ImportExportDonnees.new(type: params[:type])
.importe_donnees(params[:file_xls])
ImportExport::Questions::ImportExportDonnees.new(type: type_question)
.importe_donnees(fichier_import)
end

def erreur_import(error)
flash[:error] = error.message
redirect_to admin_import_xls_path(type: params[:type])
redirect_to admin_import_xls_path(type: type_question)
end

private
Expand All @@ -51,12 +59,12 @@ def redirection_apres_import
QuestionClicDansTexte::QUESTION_TYPE => admin_questions_clic_dans_texte_path
}

redirection_paths[params[:type]] || admin_questions_path
redirection_paths[type_question] || admin_questions_path
end

def invalide_format_xls
flash[:error] = I18n.t('.layouts.erreurs.import_question.format_invalide', format: 'XLS')
redirect_to admin_import_xls_path(type: params[:type])
redirect_to admin_import_xls_path(type: type_question)
end
end
end
22 changes: 22 additions & 0 deletions spec/features/admin/import_xls_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

require 'rails_helper'

describe 'Import XLS', type: :feature do
let!(:compte) { create :compte_superadmin }

before { connecte(compte) }

fit "importe un fichier XLS de type QuestionGlisserDeposer" do
visit admin_import_xls_path(type: 'QuestionGlisserDeposer')

stub_request(:get, %r{^https://stockagepreprod\.eva\.beta\.gouv\.fr(/.*)?$})
.to_return(status: 200, body: '', headers: {})

chemin_fichier = Rails.root.join('spec/support/import_question_glisser_deposer.xls').to_s
attach_file('question[file_xls]', chemin_fichier)
click_button 'Importer le fichier'

expect(page).to have_http_status(200)
end
end
Binary file not shown.

0 comments on commit e0d0d87

Please sign in to comment.