Prevent creation of duplicate poll voters
Note that, when taking votes from an erased user, since poll answers don't belong to poll voters, we were not migrating them in the `take_votes_from` method (and we aren't migrating them now either).
This commit is contained in:
27
spec/controllers/officing/voters_controller_spec.rb
Normal file
27
spec/controllers/officing/voters_controller_spec.rb
Normal file
@@ -0,0 +1,27 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe Officing::VotersController do
|
||||
describe "POST create" do
|
||||
it "does not create two records with two simultaneous requests", :race_condition do
|
||||
officer = create(:poll_officer)
|
||||
poll = create(:poll, officers: [officer])
|
||||
user = create(:user, :level_two)
|
||||
|
||||
sign_in(officer.user)
|
||||
|
||||
2.times.map do
|
||||
Thread.new do
|
||||
begin
|
||||
post :create, params: {
|
||||
voter: { poll_id: poll.id, user_id: user.id },
|
||||
format: :js
|
||||
}
|
||||
rescue ActionDispatch::IllegalStateError
|
||||
end
|
||||
end
|
||||
end.each(&:join)
|
||||
|
||||
expect(Poll::Voter.count).to eq 1
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user