Keep rejected statements in the vault inbox

Merged
JA
2mo ago
+66-1

Closes #3700

Fork pre-flight: https://github.com/jaysbeekay/sure/pull/418 (same branch, same commit), where its CI and review history live.

Problem

Rejecting a suggested account on an unmatched statement leaves it with no account and review_status: rejected. The Unmatched inbox only lists unmatched rows, so the statement disappears from Statement Vault, but its file stays stored. It still counts toward storage, and re-uploading the same file is refused as a duplicate. There's no way back to it from the UI. As noted on #3700, the reporter's row was in exactly this state.

Change

  • AccountStatement: new inbox scope, where(account_id: nil).where(review_status: %w[unmatched rejected]).
  • AccountStatementsController#index: the Unmatched inbox paginates inbox instead of unmatched.
  • account_statements/index.html.erb: a rejected row's suggestion cell shows the existing status badge ("Rejected") instead of "No suggestion".

A rejected statement now stays in the inbox, where it can be found and deleted. Linking it to another account by hand is a separate gap: no page offers an account picker for a statement without a suggestion, which was already true of statements that never had one.

Screenshots

The Unmatched inbox after rejecting the suggestion on checking-2026-04.csv: it stays listed with the Rejected badge. The row below still has a live suggestion, for comparison.

Light

Unmatched inbox, light theme

Dark

Unmatched inbox, dark theme

Migration notes

No migration. Rows already in this state appear in the inbox as soon as this deploys, so affected users can delete them.

Blast radius

  • The unmatched scope is unchanged. Its other readers, AccountStatement::Coverage#default_expected_start_month and #ambiguous_statement_scope, filter on suggested_account, which reject_match! clears, so rejected rows never reached them either way. A model test pins that unmatched still excludes rejected rows.
  • The Linked list (with_account) is unchanged. A rejected row later given an account keeps review_status: rejected and appears under Linked. The account_id: nil guard keeps it out of the inbox, so nothing is listed twice.
  • Duplicate detection and the storage total are deliberately unchanged: once the row is visible, both report a real stored file.
  • Out of scope: a statement that already has PDF imports still can't be destroyed (dependent: :restrict_with_error). That's existing behaviour.

Validation

  • Fail first: both new tests failed on main before the change.
    • "rejected statement stays in the inbox where it can be deleted": the row was listed before the reject and gone after it.
    • "inbox holds every accountless statement, including rejected suggestions": NoMethodError, because the scope didn't exist.
  • Mutations, each caught: index back to unmatched; scope without rejected; scope without account_id: nil; badge branch removed.
  • At this head (merged with main at e913d1d71):
    • bin/rails test: 12,301 runs, 0 failures, 0 errors, 36 skips.
    • RuboCop, erb_lint and Brakeman: clean.
    • No JavaScript changed.

Summary by CodeRabbit

  • Bug Fixes
    • Rejected account statements remain visible in the inbox, with a clear rejected status and access to their details.
    • The inbox includes unmatched and rejected statements without an account, while excluding linked statements.