Merge branch 'master' into fix/shift_creation_polls

This commit is contained in:
Raimond Garcia
2017-10-04 20:14:08 +02:00
committed by GitHub
32 changed files with 283 additions and 84 deletions

View File

@@ -8,8 +8,10 @@ class Poll::Answer < ActiveRecord::Base
validates :question, presence: true
validates :author, presence: true
validates :answer, presence: true
validates :answer, inclusion: { in: ->(a) { a.question.valid_answers }},
unless: ->(a) { a.question.blank? }
# temporary skipping validation, review when removing valid_answers
# validates :answer, inclusion: { in: ->(a) { a.question.valid_answers }},
# 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) }

View File

@@ -14,7 +14,8 @@ class Poll::Question < ActiveRecord::Base
belongs_to :author, -> { with_hidden }, class_name: 'User', foreign_key: 'author_id'
has_many :comments, as: :commentable
has_many :answers
has_many :answers, class_name: 'Poll::Answer'
has_many :question_answers, class_name: 'Poll::Question::Answer'
has_many :partial_results
belongs_to :proposal

View File

@@ -0,0 +1,9 @@
class Poll::Question::Answer < ActiveRecord::Base
belongs_to :question, class_name: 'Poll::Question', foreign_key: 'question_id'
validates :title, presence: true
def description
super.try :html_safe
end
end