Manage Mercury connections the way the provider kit does
Summary
Mercury controller convergence, C2g: managing connections. Mercury's create, update and destroy now behave as ProviderItemsController's, as Lunch Flow's do since C1g (#736). sync already matched the kit. This is the last difference between Mercury's controller and the kit's, so the controller can move onto the kit as a pure move (B8b).
Part of jaysbeekay/sure#670 (Track B, controller-layer convergence for Mercury, owner 2026-11-16). Stacked on C2f (jaysbeekay/sure#745) in fork stack #687.
Upstream draft PR: https://github.com/we-promise/sure/pull/5254 (same branch, same commit), in native stack we-promise/sure#5268 on refactor/provider-kit.
Behaviour delta (Mercury)
| Before | After | |
|---|---|---|
| Creating a connection with a blank name (the panel has a name field) | the blank name was kept, so the save failed ("Name can't be blank") | the default name, "Mercury Connection", from a new mercury_items.default_connection_name translation |
| Creating a connection with no name | "Mercury Connection" (a literal) | unchanged, now from the translation, which Family#create_mercury_item! also reads |
| Updating a connection | the cache dropped on a token or base URL change, through the controller's own helpers | unchanged, now through MercuryItem::AccountFlow.update_item_with_cache_expiration; the two helpers go |
Deleting when an error escapes unlink_all! | logged, then the connection was scheduled for deletion anyway | the error surfaces and nothing is scheduled. ProviderItem::Unlinking#unlink_all! rescues each account's failure and never re-raises, so only an error outside that loop (listing the accounts) reaches here; the destroy test stands in for it by stubbing unlink_all! to raise |
| Sync, including from the panel | already as the kit | unchanged |
What changed
MercuryItemsController#create,#update,#destroy(and#sync's guard is written as the kit's);mercury_accounts_cache_keyandmercury_accounts_cache_sensitive_update?go.config/locales/views/mercury_items/en.yml:default_connection_name.Family::MercuryConnectablereads it instead of the literal.
Demo data
No demo data needed.
Migration notes
No migration.
Verification
- Tests (fail-first): new
MercuryItemsConnectionTest, Lunch Flow's five connection tests on Mercury. On the old code the blank-name and destroy tests fail. The no-name, panel-sync and card-sync tests pass before and after, as guards. - Existing tests unedited:
MercuryItemsControllerTest(including both cache-expiry tests) and the settings controller tests pass. - Mutations, each caught: update without the cache expiration ("update expires selected mercury account cache when credentials change"); the blank name kept.
bin/rails test(full, at the C2g commit): 16,461 runs, 0 failures; the same 8ReleaseNotesWorkflowTesterrors (nonodein the test image).bin/rubocopon changed files: no offenses.bin/brakeman: no warnings.- Size: non-test +6 / -26.
- Checked against upstream AGENTS.md (blob 1a5dbebd, 2026-11-17): no deviations.
Blast radius
Family#create_mercury_item!has no caller in app or tests; its default now reads the translation.- The panel's new-connection form already defaults its name field from
mercury_items.provider_panel.default_connection_name(same English text).
Review notes
This slice mirrors Lunch Flow's C1g, whose review is answered on #736. That review also flagged the provider secret in the panel's HTML, which is being fixed separately, upstream first (see jaysbeekay/sure#670).