fix: preserve timer broadcast after logging

This commit is contained in:
Daniel Schädler 2026-04-30 12:08:00 +02:00
parent fe6533a40c
commit 8f965ad99e
2 changed files with 30 additions and 1 deletions

View File

@ -9,7 +9,9 @@ class TournamentTransactionLogger
raise 'Tournament transaction log writes must happen inside a transaction' raise 'Tournament transaction log writes must happen inside a transaction'
end end
tournament.lock! # Lock a fresh row instance so callers keep saved_change_to_* state for
# after_commit callbacks on the object they just updated.
Tournament.lock.find(tournament.id)
end end
def record!(tournament:, user:, action:, message:, metadata: {}) def record!(tournament:, user:, action:, message:, metadata: {})

View File

@ -27,5 +27,32 @@ RSpec.describe TournamentTransactionLogger do
expect(second.sequence).to eq(2) expect(second.sequence).to eq(2)
expect(tournament.transaction_log_entries.order(:sequence).pluck(:message)).to eq(%w[first second]) expect(tournament.transaction_log_entries.order(:sequence).pluck(:message)).to eq(%w[first second])
end end
it 'does not clear pending after_commit change tracking on the caller tournament' do
tournament = create(:tournament)
user = tournament.owner
old_timer = { timestamp: nil, timer_mode: nil, timer_reason: nil, timer_reason_text: nil }
Tournament.transaction do
tournament.update!(
timestamp: 2.minutes.from_now,
timer_mode: 'countdown',
timer_reason: 'tournament_start'
)
new_timer = { timestamp: tournament.timestamp.iso8601, timer_mode: 'countdown',
timer_reason: 'tournament_start', timer_reason_text: nil }
expect(tournament.saved_change_to_timestamp?).to be(true)
described_class.record_timer_changed!(
tournament: tournament,
user: user,
old_timer: old_timer,
new_timer: new_timer
)
expect(tournament.saved_change_to_timestamp?).to be(true)
end
end
end end
end end