Keep rejected statements in the vault inbox

Closed
JA
2mo ago
+66-1

Summary

Rejecting a suggested account on an unmatched statement no longer makes the statement vanish from Statement Vault. It stays in the Unmatched inbox with a "Rejected" badge, where it can be found and deleted, so its file no longer sits unreachable while counting toward storage and blocking re-uploads as a duplicate.

Fixes jaysbeekay/sure#417
Fork pre-flight for upstream we-promise/sure#3700. Upstream PR: https://github.com/we-promise/sure/pull/4299 (same branch, same commit). Base is mirror/upstream-main at the same commit as upstream main (d55eac220), so the diff is what upstream will see; the upstream PR will be opened from this same branch and commit.

What changed

  • b77ea9bdc Keep rejected statements in the vault inbox

  • 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 account_statement_status_badge ("Rejected") instead of "No suggestion".

  • Tests: one controller test, one model test.

Demo data

No demo data needed: the change is a listing fix for an existing state, reached by clicking Reject on any suggested statement.

Screenshots

Unmatched inbox after clicking Reject suggestion on checking-2026-04.csv. The statement stays listed with the Rejected badge and its View action; the row below still has a live suggestion for comparison. Captured from a system-test browser session at b77ea9bdc.

Light

Unmatched inbox, light theme

Dark

Unmatched inbox, dark theme

Migration notes

No migration. Rows already in this state (account_id: nil, review_status: rejected) appear in the inbox as soon as this deploys, so affected users can delete them from the UI.

Verification

  • Fail-first on upstream/main (d55eac220): rejected statement stays in the inbox where it can be deleted found the row before the reject and 0 rows after it. inbox holds every accountless statement, including rejected suggestions errored with NoMethodError (no scope).
  • Mutations, each failing at least one test: index back to unmatched (controller test); scope without rejected (both); scope without account_id: nil (model test); badge branch removed (controller test).
  • bin/rails test test/controllers/account_statements_controller_test.rb test/models/account_statement_test.rb test/models/account_statement: 88 runs, 0 failures.
  • bin/rails test (full): 11544 runs, 1 failure, 0 errors, 34 skips. The failure is SnaptradeAccount::ActivitiesProcessorTest#test_calculates_realized_gain/loss_for_option_buy_and_sell_using_per-contract_prices (expected 7000.00, got 6999.79). It fails identically on unmodified upstream/main d55eac220 and touches nothing in this diff. Already tracked upstream as we-promise/sure#4144.
  • Fork CI at b77ea9bdc: test_unit fails on that same single test only (11544 runs, 1 failure, 0 errors); test_system, lint, lint_js, scan_ruby, scan_js and Codacy green. cubic did not review: monthly line limit reached until 1 November.
  • bin/rubocop (changed files): no offenses.
  • bundle exec erb_lint app/views/account_statements/index.html.erb: no errors.
  • npm run lint: not applicable, no JavaScript changed.
  • bin/brakeman --no-pager: 0 warnings.

Blast radius

  • unmatched scope is unchanged. Its other readers, AccountStatement::Coverage#default_expected_start_month and #ambiguous_statement_scope, both filter where(suggested_account: account), which reject_match! clears, so rejected rows never reached them either way. The model test pins that unmatched still excludes rejected rows.
  • Linked list (with_account) is unchanged. A rejected row later given an account through the metadata form keeps review_status: rejected (sync_review_status returns early for rejected) and appears under Linked; the account_id: nil guard in inbox keeps it out of the inbox, so nothing is listed twice. The model test covers that row.
  • Duplicate detection (duplicate_for) and @total_storage_bytes are deliberately unchanged: once the row is visible, both are reporting a real stored file.
  • Out of scope, from the Gatekeeper review on #417: pdf_imports is dependent: :restrict_with_error, so a statement that already has PDF imports still cannot be destroyed. That is pre-existing and unchanged here.