diff --git a/app/controllers/officing/voters_controller.rb b/app/controllers/officing/voters_controller.rb index de321b96b..f1c042770 100644 --- a/app/controllers/officing/voters_controller.rb +++ b/app/controllers/officing/voters_controller.rb @@ -13,16 +13,19 @@ class Officing::VotersController < Officing::BaseController def create @poll = Poll.find(voter_params[:poll_id]) @user = User.find(voter_params[:user_id]) - @voter = Poll::Voter.new(document_type: @user.document_type, - document_number: @user.document_number, - user: @user, - poll: @poll, - origin: "booth", - officer: current_user.poll_officer, - booth_assignment: current_booth.booth_assignments.find_by(poll: @poll), - officer_assignment: officer_assignment(@poll)) - @user.with_lock { @voter.save! } + @user.with_lock do + @voter = Poll::Voter.new(document_type: @user.document_type, + document_number: @user.document_number, + user: @user, + poll: @poll, + origin: "booth", + officer: current_user.poll_officer, + booth_assignment: current_booth.booth_assignments.find_by(poll: @poll), + officer_assignment: officer_assignment(@poll)) + + @voter.save! + end end private diff --git a/spec/controllers/officing/voters_controller_spec.rb b/spec/controllers/officing/voters_controller_spec.rb index e1a611755..33906db84 100644 --- a/spec/controllers/officing/voters_controller_spec.rb +++ b/spec/controllers/officing/voters_controller_spec.rb @@ -15,7 +15,7 @@ describe Officing::VotersController do voter: { poll_id: poll.id, user_id: user.id }, format: :js } - rescue ActionDispatch::IllegalStateError + rescue ActionDispatch::IllegalStateError, ActiveRecord::RecordInvalid end end.each(&:join)