Don't save the answer if the voter is not recorded
Up until now, we were assuming the voter was valid, but were not raising an exception if it wasn't. And in the user interface everything seemed to be working properly. We were having this issue when skipping verification, when there could be voters without a document number, which would be considered invalid. Raising an exception when failing to save the voter and making sure the answer and the voter are saved inside a transaction solves the problem.
This commit is contained in:
@@ -9,9 +9,7 @@ class Polls::QuestionsController < ApplicationController
|
||||
token = params[:token]
|
||||
|
||||
answer.answer = params[:answer]
|
||||
answer.touch if answer.persisted?
|
||||
answer.save!
|
||||
answer.record_voter_participation(token)
|
||||
answer.save_and_record_voter_participation(token)
|
||||
|
||||
@answers_by_question_id = { @question.id => params[:answer] }
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user