Skip to content

Fix raw state integers + add sentry logs#73

Open
JuanVqz wants to merge 2 commits intomainfrom
fix-raw-state-integers
Open

Fix raw state integers + add sentry logs#73
JuanVqz wants to merge 2 commits intomainfrom
fix-raw-state-integers

Conversation

@JuanVqz
Copy link
Member

@JuanVqz JuanVqz commented Mar 10, 2026

Problem

Both DailyPuzzleJob and PuzzleInventoryCheckJob queried for approved puzzles using the raw integer state: 0 instead of the named enum scope:

# Fragile — breaks silently if enum values change
Puzzle.where(sent_at: nil, state: 0)
Puzzle.where(state: 0, sent_at: nil)

The integer 0 maps to approved today per the enum definition, but this is implicit and will silently return wrong results if the enum ever changes.

Fix

Puzzle.approved.where(sent_at: nil)

Tests

Added test files for both jobs (neither had any tests):

DailyPuzzleJobTest

  • Only selects approved puzzles, not pending or rejected
  • Only selects puzzles that have not been sent yet
  • Marks the selected puzzle as archived and sets sent_at
  • Does nothing when no approved unsent puzzles exist

PuzzleInventoryCheckJobTest

  • Sends notification when fewer than 5 approved unsent puzzles exist
  • Does not send notification when 5 or more approved unsent puzzles exist
  • Only counts approved puzzles, not pending or rejected
  • Only counts unsent puzzles

JuanVqz added 2 commits March 10, 2026 15:58
Using state: 0 relied on knowing the integer value of the approved enum,
which breaks silently if values change. Both DailyPuzzleJob and
PuzzleInventoryCheckJob now use Puzzle.approved.where(sent_at: nil).
@JuanVqz JuanVqz requested review from mateusdeap and torresga March 10, 2026 22:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant