diff --git a/app/controllers/candidate_controller.rb b/app/controllers/candidate_controller.rb index aa6cb4c..fb7df1c 100644 --- a/app/controllers/candidate_controller.rb +++ b/app/controllers/candidate_controller.rb @@ -3,7 +3,7 @@ class CandidateController < ApplicationController end def question - @question = Question.where(input_type: 'live-coder').order("RAND()").first + @question = Question.order("RAND()").first # .where(input_type: 'live-coder') @status = QuizStatus.new(Candidate.order("RAND()").first) @answer = @question.answers.order("RAND()").first end diff --git a/app/views/candidate/question.html.erb b/app/views/candidate/question.html.erb index 942631c..be9a415 100644 --- a/app/views/candidate/question.html.erb +++ b/app/views/candidate/question.html.erb @@ -27,27 +27,11 @@ - + +<% end %> diff --git a/app/workers/quiz_status.rb b/app/workers/quiz_status.rb index 8b5af02..0a5a747 100644 --- a/app/workers/quiz_status.rb +++ b/app/workers/quiz_status.rb @@ -21,26 +21,10 @@ class QuizStatus on_summary && candidate.answered_questions.count == candidate.questions.count end - # query($TotalQuestions); - # $TotalQuestions = $result->num_rows + 1; - # - # $progressBarValue = round($questionId/$TotalQuestions * 100); - # $_SESSION['pBarValue'] = $progressBarValue; - # - # $pValue = $_SESSION['pBarValue']; - # - # if(!isset($_GET['qid'])) { ?> - #
- #
- # % - #
- #
- # + def progress + answs = candidate.answered_questions.count.to_f + total = candidate.quiz.questions.count.to_f + + (answs / total * 100).round.to_i + end end diff --git a/test/workers/quiz_status_test.rb b/test/workers/quiz_status_test.rb index 8dffbe1..818d6b9 100644 --- a/test/workers/quiz_status_test.rb +++ b/test/workers/quiz_status_test.rb @@ -56,4 +56,25 @@ class QuizStatusTest < ActiveSupport::TestCase assert status.can_submit end + + test "richard is at 100%" do + richard = candidates :richard + status = QuizStatus.new richard + + assert_equal 100, status.progress + end + + test "roy is 20% done" do + roy = candidates :roy + status = QuizStatus.new roy + + assert_equal 20, status.progress + end + + test "martha is 0% done" do + martha = candidates :martha + status = QuizStatus.new martha + + assert_equal 0, status.progress + end end