class Quiz < ActiveRecord::Base
  has_many :questions, :dependent => :destroy
  validates :title, :category, :description, presence: true
  validates :title, :category, :description, length: {minimum: 3, maximum: 254, too_short: "must have at least %{count} words", too_long: "must have at most %{count} words"}

  # Total score of a quiz
  def self.total_score(id)
    total_score = 0
    questions = Quiz.find(id).questions
    questions.each do |question|
      total_score += question.score
    end
    total_score
  end

end
