From 35cbe68f00c00c4a22fb9eb3d3fb8ba09477f06f Mon Sep 17 00:00:00 2001 From: Mark Moser Date: Fri, 11 Nov 2016 14:26:07 -0600 Subject: [PATCH] fix bug calculating quiz completion with inactive questions --- app/workers/quiz_status.rb | 7 ++++--- test/fixtures/questions.yml | 29 +++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/app/workers/quiz_status.rb b/app/workers/quiz_status.rb index df3e50f..a4a5977 100644 --- a/app/workers/quiz_status.rb +++ b/app/workers/quiz_status.rb @@ -11,7 +11,7 @@ class QuizStatus end def on_summary - candidate.submitted_answers.count == candidate.questions.count + candidate.submitted_answers.count == candidate.questions.where(active: true).count end delegate :completed, to: :candidate @@ -19,12 +19,12 @@ class QuizStatus def can_submit on_summary && no_finish_later && - candidate.answered_questions.count == candidate.questions.count + candidate.answered_questions.count == candidate.questions.where(active: true).count end def progress answs = candidate.answered_questions.count.to_f - total = candidate.quiz.questions.count.to_f + total = candidate.quiz.questions.where(active: true).count.to_f (answs / total * 100).round.to_i end @@ -35,6 +35,7 @@ class QuizStatus inner join questions q on q.id = a.question_id where q.input_type = 'live_code' and a.answer like "%later: 'true'%" + and q.active = true and a.candidate_id = #{candidate.id}) result = ActiveRecord::Base.connection.exec_query(sql).to_hash.first result['todos'].zero? diff --git a/test/fixtures/questions.yml b/test/fixtures/questions.yml index b498ff2..97c7d00 100644 --- a/test/fixtures/questions.yml +++ b/test/fixtures/questions.yml @@ -112,6 +112,35 @@ fed10: sort: 9 active: true +fed11: + quiz: fed + question: nope, nope nope? + category: Performance + input_type: checkbox + input_options: + - "Live long and prosper" + - "Who ya gonna call?" + - "Who you calling Scruffy?" + - "J.J. Abrams" + - "wibbly wobbly, timey wimey" + sort: 91 + active: false + +fed12: + quiz: fed + question: yet, another old fake question + category: Performance + input_type: checkbox + input_options: + - "Live long and prosper" + - "Who ya gonna call?" + - "Who you calling Scruffy?" + - "J.J. Abrams" + - "wibbly wobbly, timey wimey" + sort: 91 + active: false + + admin1: quiz: admin question: 'You have a question you want to ask.'