Add validations for changing votation type
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user