Remove poll votation types

Unfortunately this feature wasn't properly reviewed and tested, and it
had many bugs, some of them critical and hard to fix, like validations
being skipped in concurrent requests.

So we're removing it before releasing version 1.1. We might add it back
in the future if we manage to solve the critical issues.

This commit reverts commit 836f9ba7.
This commit is contained in:
Javi Martín
2019-10-30 18:48:55 +01:00
parent f3df3f4fbc
commit af7c37634d
53 changed files with 173 additions and 2244 deletions

View File

@@ -18,22 +18,14 @@ class Poll::Question < ApplicationRecord
inverse_of: :question,
dependent: :destroy
has_many :partial_results
has_many :pair_answers
has_one :votation_type, as: :questionable, inverse_of: :questionable
belongs_to :proposal
attr_accessor :enum_type, :max_votes, :prioritization_type
validates_translation :title, presence: true, length: { minimum: 4 }
validates :author, presence: true
validates :poll_id, presence: true, if: proc { |question| question.poll.nil? }
validates_associated :votation_type
accepts_nested_attributes_for :question_answers, reject_if: :all_blank, allow_destroy: true
delegate :enum_type, :max_votes, :prioritization_type, :max_groups_answers,
to: :votation_type, allow_nil: true
scope :by_poll_id, ->(poll_id) { where(poll_id: poll_id) }
scope :sort_for_list, -> { order("poll_questions.proposal_id IS NULL", :created_at) }
@@ -71,28 +63,14 @@ class Poll::Question < ApplicationRecord
end
def answers_total_votes
question_answers.visibles.reduce(0) { |total, question_answer| total + question_answer.total_votes }
question_answers.reduce(0) { |total, question_answer| total + question_answer.total_votes }
end
def most_voted_answer_id
question_answers.max_by(&:total_votes).id
end
def answers_with_read_more?
question_answers.visibles.any? do |answer|
answer.description.present? || answer.images.any? || answer.documents.present? || answer.videos.present?
end
end
def user_can_vote(user)
max_votes.nil? || max_votes > answers.where(author: user).count
end
def is_positive_negative?
votation_type.present? && enum_type == "positive_negative_open"
end
def possible_answers
question_answers.visibles.joins(:translations).pluck("poll_question_answer_translations.title")
question_answers.joins(:translations).pluck("poll_question_answer_translations.title")
end
end