Keep SQL pending checks consistent with Transaction#pending?

Merged
JA
3mo ago
+948-84

Summary

Keep SQL pending checks in step with Transaction#pending?. A shared predicate avoids PostgreSQL boolean casts on stored JSON text and is used across matching, analytics, and import cleanup.

Fork pre-flight for the upstream PR. The branch is based on upstream main and targets mirror/upstream-main.

Upstream PR: we-promise/sure#3557

Fixes we-promise/sure#3556

What changed

  • Add reusable pending and not-pending SQL predicates based on ActiveModel boolean semantics.
  • Replace provider-specific raw pending checks in import, reconciliation, analytics, and cleanup queries.
  • Build the correlated SQL constant from fixed model constants, without a database connection during class loading.
  • Align stale unmatched SimpleFIN counts with the pending filter used by cleanup.
  • Add parity tests for booleans, nil, Rails false values, unknown strings, and numeric values, plus reader-level regressions.

26 files changed: 782 insertions, 66 deletions.

Demo data

No demo data needed; this change has no demo-facing surface.

Migration notes

No migration.

Verification

  • bin/rails tailwindcss:build: completed.
  • Focused Minitest paths covering the changed readers and models: 215 runs, 874 assertions, 0 failures, 0 errors, 0 skips.
  • bin/rubocop app/models/entry.rb app/models/entry_search.rb app/models/transaction.rb: no offenses.
  • bin/brakeman -q: 0 security warnings; 9 existing warnings ignored.
  • git diff --check: clean.

Blast radius

The shared pending SQL predicate affects provider-import matching, entry reconciliation and status filters, income and goal calculations, and SimpleFIN stale-pending cleanup. Tests cover SQL parity and the touched read paths.