diff --git a/app/models/restitution/export_positionnement.rb b/app/models/restitution/export_positionnement.rb index baf5e06de..d08b4e651 100644 --- a/app/models/restitution/export_positionnement.rb +++ b/app/models/restitution/export_positionnement.rb @@ -70,7 +70,7 @@ def remplis_reponses_par_code(sheet, ligne, code, evenements) end def pourcentage_reussite(evenements) - scores = evenements.map { |e| [e.donnees['scoreMax'], e.donnees['score']] } + scores = evenements.map { |e| [e.donnees['scoreMax'] || 0, e.donnees['score'] || 0] } score_max, score = scores.transpose.map(&:sum) score_max.zero? ? 0 : (score * 100 / score_max).round end diff --git a/spec/models/restitution/export_positionnement_spec.rb b/spec/models/restitution/export_positionnement_spec.rb index 634efd5f5..4e460161a 100644 --- a/spec/models/restitution/export_positionnement_spec.rb +++ b/spec/models/restitution/export_positionnement_spec.rb @@ -49,6 +49,10 @@ score: 1, scoreMax: 2, metacompetence: 'renseigner_horaires' } + create :evenement_reponse, + partie: partie, + donnees: { question: 'LOdi3', + metacompetence: 'parametres' } create :evenement_reponse, partie: partie, donnees: { intitule: intitule_question2, @@ -80,7 +84,10 @@ question2 = worksheet.row(4) expect(question2[0]).to be_nil question2 = worksheet.row(5) - expect(question2[0]).to eq('LOdi4') + expect(question2[0]).to eq('LOdi3') + question2 = worksheet.row(6) + expect(question2[3]).to be_nil + expect(question2[4]).to be_nil expect(question2[1]).to eq(intitule_question2) expect(question2[2]).to eq('Le chat de Mme Coupin') expect(question2[3]).to be_nil