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:
Javi Martín
2020-08-06 21:44:09 +02:00
parent 50372f4370
commit 24ccf23ed8
3 changed files with 22 additions and 9 deletions

View File

@@ -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