Merge pull request #5761 from consuldemocracy/officing_voters_lock

Include voter initialization in officing voters lock
This commit is contained in:
Javi Martín
2024-11-07 11:37:25 +01:00
committed by GitHub
2 changed files with 13 additions and 10 deletions

View File

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

View File

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