blob: e2a68d1f38134e647392ee082fa7a44091c43459 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
|
# frozen_string_literal: true
class VoteValidator < ActiveModel::Validator
def validate(vote)
vote.errors.add(:base, I18n.t('polls.errors.expired')) if vote.poll.expired?
if vote.poll.multiple? && vote.poll.votes.where(account: vote.account, choice: vote.choice).exists?
vote.errors.add(:base, I18n.t('polls.errors.already_voted'))
elsif vote.poll.votes.where(account: vote.account).exists?
vote.errors.add(:base, I18n.t('polls.errors.already_voted'))
end
end
end
|