From b34d2b51174b511d59fa324d9f42abc75a1fa09a Mon Sep 17 00:00:00 2001 From: Marius Peter Date: Thu, 2 Jan 2025 19:11:34 +0100 Subject: Ensure session[:id] before scoring: all tests now pass. Never too late for all tests to pass... --- app/services/tartiflette_scoring_service.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'app/services/tartiflette_scoring_service.rb') diff --git a/app/services/tartiflette_scoring_service.rb b/app/services/tartiflette_scoring_service.rb index 6df2f0c..4e4bc76 100644 --- a/app/services/tartiflette_scoring_service.rb +++ b/app/services/tartiflette_scoring_service.rb @@ -10,11 +10,11 @@ class TartifletteScoringService end def self.submit_scores(tartiflette, scores, session) - scores.each do |criterium_id, score_params| + scores.each do |scoring_criterium_id, score_params| Score.create!( - session_id: session.id, + session_id: session[:id], tartiflette: tartiflette, - scoring_criterium_id: criterium_id, + scoring_criterium_id: scoring_criterium_id, value: score_params[:value] ) end @@ -32,6 +32,8 @@ class TartifletteScoringService raise StandardError, "Failed to update score: #{e.message}" end + private + def self.average_score(tartiflette) tartiflette.scores.average(:value).to_f end @@ -50,7 +52,7 @@ class TartifletteScoringService .scores .group_by { |score| score.scoring_criterium.category } .transform_values do |scores| - (scores.sum(&:value).to_f / scores.size).round(2) + scores.sum(&:value).to_f.round(2) end end -- cgit v1.2.3