diff --git a/app/models/concerns/questionable.rb b/app/models/concerns/questionable.rb deleted file mode 100644 index 1d0606fc6..000000000 --- a/app/models/concerns/questionable.rb +++ /dev/null @@ -1,30 +0,0 @@ -module Questionable - extend ActiveSupport::Concern - - included do - has_one :votation_type, as: :questionable, dependent: :destroy - accepts_nested_attributes_for :votation_type - delegate :max_votes, :multiple?, :vote_type, to: :votation_type, allow_nil: true - end - - def unique? - votation_type.nil? || votation_type.unique? - end - - def find_or_initialize_user_answer(user, title) - answer = answers.find_or_initialize_by(find_by_attributes(user, title)) - answer.answer = title - answer - end - - private - - def find_by_attributes(user, title) - case vote_type - when "unique", nil - { author: user } - when "multiple" - { author: user, answer: title } - end - end -end diff --git a/app/models/poll/question.rb b/app/models/poll/question.rb index b860195c5..813b7882e 100644 --- a/app/models/poll/question.rb +++ b/app/models/poll/question.rb @@ -1,7 +1,6 @@ class Poll::Question < ApplicationRecord include Measurable include Searchable - include Questionable acts_as_paranoid column: :hidden_at include ActsAsParanoidAliases @@ -19,6 +18,7 @@ class Poll::Question < ApplicationRecord inverse_of: :question, dependent: :destroy has_many :partial_results + has_one :votation_type, as: :questionable, dependent: :destroy belongs_to :proposal validates_translation :title, presence: true, length: { minimum: 4 } @@ -26,6 +26,9 @@ class Poll::Question < ApplicationRecord validates :poll_id, presence: true, if: proc { |question| question.poll.nil? } accepts_nested_attributes_for :question_options, reject_if: :all_blank, allow_destroy: true + accepts_nested_attributes_for :votation_type + + delegate :max_votes, :multiple?, :vote_type, to: :votation_type, allow_nil: true scope :by_poll_id, ->(poll_id) { where(poll_id: poll_id) } @@ -82,4 +85,25 @@ class Poll::Question < ApplicationRecord def options_with_read_more question_options.select(&:with_read_more?) end + + def unique? + votation_type.nil? || votation_type.unique? + end + + def find_or_initialize_user_answer(user, title) + answer = answers.find_or_initialize_by(find_by_attributes(user, title)) + answer.answer = title + answer + end + + private + + def find_by_attributes(user, title) + case vote_type + when "unique", nil + { author: user } + when "multiple" + { author: user, answer: title } + end + end end