Manage Lunch Flow connections the way the provider kit does

Merged
JA
2d ago
+67-22

Summary

Lunch Flow controller convergence, C1g: managing connections. Lunch Flow's create, update, destroy and sync now behave as ProviderItemsController's do, which is the last difference left between Lunch Flow's controller and the kit's. The controller can then move onto the kit as a pure move (B7b).

Part of #5003 (Track B, controller-layer convergence, option (b), decided 2026-11-16).

Stacked on #5246. Fork pre-flight: jaysbeekay/sure#736 (same branch, same commit; its CI, Gatekeeper review and screenshot history live there).

Behaviour delta (Lunch Flow)

BeforeAfter
Creating a connection with a blank name ("")the blank name was kept, so the save failed ("Name can't be blank")the default name, "Lunch Flow Connection", from a new lunchflow_items.default_connection_name translation
Creating a connection with no name"Lunch Flow Connection" (a literal)unchanged, now from the translation; the panel's initialised record and Family#create_lunchflow_item! read it too
Updating a connectionthe cache dropped on an API key or base URL changeunchanged, now through LunchflowItem::AccountFlow.update_item_with_cache_expiration; the panel is also given lunchflow_items (which Lunch Flow's single-connection panel doesn't read)
Deleting when an error escapes unlink_all!logged, then the connection was scheduled for deletion anywaythe error surfaces and nothing is scheduled. ProviderItem::Unlinking already rescues each account's failure, so only an error listing the accounts (a database failure) reaches here
A sync posted from the panel (source=panel)redirect (406 for a Turbo request)the panel re-renders with "sync in progress". Lunch Flow's card doesn't send source=panel, so nothing reachable from its UI changes

What changed

  • LunchflowItemsController#create, #update, #destroy, #sync: as the kit's; the private cache-key helper goes.
  • config/locales/views/lunchflow_items/en.yml: default_connection_name. _lunchflow_panel.html.erb and Family::LunchflowConnectable use it instead of the literal.

Screenshots

Settings > Bank sync, Lunch Flow's panel, captured headlessly in Chrome at 1100 px from the fixture family: before at the base head (b575b994), after at this PR's head (960475e3). The panel looks the same: the default name now comes from a translation, but the form has no name field, and nothing in Lunch Flow's UI posts a blank name or source=panel.

No connection yet (the "Save and connect" form for the record the panel initialises with the default name):

BeforeAfter
Before: Lunch Flow panel with Save and connectAfter: Lunch Flow panel with Save and connect, unchanged

An existing connection ("Update connection"):

BeforeAfter
Before: Lunch Flow panel with Update connectionAfter: Lunch Flow panel with Update connection, unchanged

Demo data

No demo data needed.

Migration notes

No migration.

Verification

  • Tests (fail-first): new LunchflowItemsConnectionTest (5 tests): blank name; no name (a guard, passes before and after); sync from the panel; sync from the card (a guard); destroy with an error escaping unlink_all!. On the old code the blank-name, panel-sync and destroy tests fail.
  • Mutations, each caught: update without the cache expiration (the existing API-key and base-URL cache tests); the blank name kept; the panel sync not rendered.
  • Existing tests unedited: LunchflowItemsControllerTest, the cache tests and the settings controller tests pass.
  • bin/rails test (full, at the C1g commit): 16,386 runs, 0 failures; the same 8 ReleaseNotesWorkflowTest errors (no node in the test image).
  • bin/rubocop, erb_lint: no offenses. bin/brakeman: no warnings.
  • Size: non-test +10 / -22.
  • Checked against upstream AGENTS.md (blob 1a5dbebd, 2026-11-17): no deviations.

Blast radius

  • Family#create_lunchflow_item! has no caller in app or tests; its default now reads the translation.
  • The panel's first_or_initialize(name:) only sets the unsaved record's name; the form posts no name field.

Review notes

A code review of the diff before commit raised nine points. Taken: the default name's two other literals now read the translation. Noted, not changed:

  • the reviewer worried that the panel's blank password field would erase the API key on update. It doesn't: the field is a text_field with type: :password, which renders the stored value, so the key is resubmitted. That means the Lunch Flow API key is in the provider settings page's HTML: a probe test confirmed response.body contains the fixture key. This predates this stack and is not changed here. Brex's credential fields (B4b) omit the stored token, and Lunch Flow's panel moves onto that shape in its view slices; worth fixing on its own sooner.
  • because the key is resubmitted, every panel update counts as a credential change and drops the accounts cache, as before (C1c) and as on the kit;
  • the lunchflow_items panel local is unused by Lunch Flow's panel; it is passed so the controller move is pure;
  • the four actions now duplicate the kit's until B7b swaps the controller for a subclass.

Summary by cubic

Makes Lunch Flow's connection actions behave like the provider kit's, closing the last controller difference so the controller can move onto the kit as a pure move.

  • Creating a connection with a blank name now uses the default "Lunch Flow Connection" from a new translation instead of failing validation; the panel and Family#create_lunchflow_item! read the same translation.
  • Updating expires the accounts cache through LunchflowItem::AccountFlow instead of the controller's own cache-key helper, and hands the panel its lunchflow_items.
  • Destroying no longer swallows an error escaping unlink_all!; the error surfaces and the item isn't scheduled for deletion.
  • A sync posted from the panel re-renders the panel with "sync in progress" instead of returning a 406 redirect; nothing in Lunch Flow's UI sends source=panel, so reachable behavior is unchanged.

Part of #5003 (Track B, controller-layer convergence).