Correct answer inclusion validation for no question scenario
This commit is contained in:
@@ -9,7 +9,8 @@ class Poll::Answer < ActiveRecord::Base
|
||||
validates :author, presence: true
|
||||
validates :answer, presence: true
|
||||
|
||||
validates :answer, inclusion: { in: ->(a) { a.question.question_answers.pluck(:title) }}
|
||||
validates :answer, inclusion: { in: ->(a) { a.question.question_answers.pluck(:title) }},
|
||||
unless: ->(a) { a.question.blank? }
|
||||
|
||||
scope :by_author, ->(author_id) { where(author_id: author_id) }
|
||||
scope :by_question, ->(question_id) { where(question_id: question_id) }
|
||||
|
||||
@@ -10,8 +10,9 @@ class Poll::PartialResult < ActiveRecord::Base
|
||||
validates :question, presence: true
|
||||
validates :author, presence: true
|
||||
validates :answer, presence: true
|
||||
validates :answer, inclusion: {in: ->(a) { a.question.question_answers.pluck(:title) }}
|
||||
validates :origin, inclusion: {in: VALID_ORIGINS}
|
||||
validates :answer, inclusion: { in: ->(a) { a.question.question_answers.pluck(:title) }},
|
||||
unless: ->(a) { a.question.blank? }
|
||||
validates :origin, inclusion: { in: VALID_ORIGINS }
|
||||
|
||||
scope :by_author, ->(author_id) { where(author_id: author_id) }
|
||||
scope :by_question, ->(question_id) { where(question_id: question_id) }
|
||||
|
||||
Reference in New Issue
Block a user