docbrown/app/models/poll_skip.rb
yheuhtozr e45536af37
app/models i18n (#16124)
* app/models etc i18n

* delete ja.yml

* fix for PR review

* fix for spec

* delete ja.yml

* fix for spec updated
2022-02-03 13:41:42 -05:00

22 lines
731 B
Ruby

# @note When we destroy the related user, it's using dependent:
# :delete for the relationship. That means no before/after
# destroy callbacks will be called on this object.
#
# @note When we destroy the related poll, it's using dependent:
# :delete for the relationship. That means no before/after
# destroy callbacks will be called on this object.
class PollSkip < ApplicationRecord
belongs_to :poll
belongs_to :user
validate :one_vote_per_poll_per_user
private
def one_vote_per_poll_per_user
return false unless poll
return false unless poll.vote_previously_recorded_for?(user_id: user_id)
errors.add(:base, I18n.t("models.poll_skip.cannot_vote_more_than_once"))
end
end