Add validations for changing votation type

This commit is contained in:
taitus
2025-08-06 12:13:13 +02:00
parent 9ff167d040
commit b4b00487cc
5 changed files with 66 additions and 25 deletions

View File

@@ -1,6 +1,8 @@
class VotationType < ApplicationRecord
belongs_to :questionable, polymorphic: true
validate :cannot_be_open_ended_if_question_has_options
QUESTIONABLE_TYPES = %w[Poll::Question].freeze
enum :vote_type, { unique: 0, multiple: 1, open: 2 }
@@ -18,4 +20,10 @@ class VotationType < ApplicationRecord
def max_votes_required?
multiple?
end
def cannot_be_open_ended_if_question_has_options
if questionable&.question_options&.any? && !accepts_options?
errors.add(:vote_type, :cannot_change_to_open_ended)
end
end
end