From 92b2f72fb8eb36d3951d15973dbe0055a2cf7a37 Mon Sep 17 00:00:00 2001 From: Martin Gruner Date: Tue, 7 Sep 2021 14:28:00 +0200 Subject: [PATCH] Maintenance: Fix race condition in ticket number generator tests. --- spec/models/ticket/number/increment_spec.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spec/models/ticket/number/increment_spec.rb b/spec/models/ticket/number/increment_spec.rb index 1c3651a9e..47bcda9d5 100644 --- a/spec/models/ticket/number/increment_spec.rb +++ b/spec/models/ticket/number/increment_spec.rb @@ -82,7 +82,11 @@ RSpec.describe Ticket::Number::Increment do describe '.check' do context 'for tickets with increment-style numbers' do - let(:ticket) { create(:ticket, number: ticket_number) } + let(:ticket) do + # There might be conflicts with the hardcoded ticket number + # and the one from the welcome ticket, so use find_by || create. + Ticket.find_by(number: ticket_number) || create(:ticket, number: ticket_number) + end let(:ticket_number) { "#{Setting.get('system_id')}0001" } let(:check_query) { ticket.subject_build(ticket.title) }