fix: preserve timer broadcast after logging
This commit is contained in:
parent
fe6533a40c
commit
8f965ad99e
|
|
@ -9,7 +9,9 @@ class TournamentTransactionLogger
|
|||
raise 'Tournament transaction log writes must happen inside a transaction'
|
||||
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
|
||||
|
||||
def record!(tournament:, user:, action:, message:, metadata: {})
|
||||
|
|
|
|||
|
|
@ -27,5 +27,32 @@ RSpec.describe TournamentTransactionLogger do
|
|||
expect(second.sequence).to eq(2)
|
||||
expect(tournament.transaction_log_entries.order(:sequence).pluck(:message)).to eq(%w[first second])
|
||||
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
|
||||
|
|
|
|||
Loading…
Reference in New Issue