Add questions with mutiple answers to polls public interface

The `reload` method added to max_votes validation is needed because the
author gets here with some changes because of the around_action
`switch_locale`, which adds some changes to the current user record and
therefore, the lock method raises an exception when trying to lock it
requiring us to save or discard those record changes.
This commit is contained in:
decabeza
2022-09-02 16:41:17 +02:00
committed by Senén Rodero Rodríguez
parent 3da4112d94
commit 36e452437e
11 changed files with 121 additions and 5 deletions

View File

@@ -10,4 +10,21 @@ module Questionable
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