Files
nairobi/spec/controllers/polls/answers_controller_spec.rb
Javi Martín 07202fea10 Add and apply Style/RedundantBegin rubocop rule
We're about to add code which might fall into the `RedundantBegin`
category, so we're adding the rule in order to prevent that.
2024-10-30 15:57:44 +01:00

24 lines
677 B
Ruby

require "rails_helper"
describe Polls::AnswersController do
describe "POST create" do
it "doesn't create duplicate records on simultaneous requests", :race_condition do
question = create(:poll_question_multiple, :abc)
sign_in(create(:user, :level_two))
2.times.map do
Thread.new do
post :create, params: {
question_id: question.id,
option_id: question.question_options.find_by(title: "Answer A").id,
format: :js
}
rescue ActionDispatch::IllegalStateError, ActiveRecord::RecordInvalid
end
end.each(&:join)
expect(Poll::Answer.count).to eq 1
end
end
end