big start on QuizStatus
This commit is contained in:
@ -1,4 +1,6 @@
|
||||
class Candidate < ApplicationRecord
|
||||
belongs_to :quiz
|
||||
has_many :questions, through: :quiz
|
||||
has_many :answers
|
||||
belongs_to :recruiter, class_name: "User"
|
||||
|
||||
@ -8,6 +10,14 @@ class Candidate < ApplicationRecord
|
||||
validates_presence_of :test_hash
|
||||
validates_uniqueness_of :test_hash
|
||||
|
||||
def submitted_answers
|
||||
answers.where(submitted: true)
|
||||
end
|
||||
|
||||
def answered_questions
|
||||
answers.where.not(answer: nil)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def generate_test_hash
|
||||
|
@ -1,3 +1,4 @@
|
||||
class Quiz < ApplicationRecord
|
||||
has_many :questions
|
||||
has_many :candidates
|
||||
end
|
||||
|
23
app/workers/quiz_status.rb
Normal file
23
app/workers/quiz_status.rb
Normal file
@ -0,0 +1,23 @@
|
||||
class QuizStatus
|
||||
attr_reader :candidate
|
||||
|
||||
def initialize candidate
|
||||
@candidate = Candidate.find(candidate.to_i)
|
||||
end
|
||||
|
||||
def started
|
||||
candidate.answers.count > 0
|
||||
end
|
||||
|
||||
def on_summary
|
||||
candidate.submitted_answers.count == candidate.questions.count
|
||||
end
|
||||
|
||||
def completed
|
||||
candidate.completed
|
||||
end
|
||||
|
||||
def can_submit
|
||||
on_summary && candidate.answered_questions.count == candidate.questions.count
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user