Generate the provider controller and routes on the provider kit
Summary
Provider kit Track B, B6c: provider:family generates a provider's controller and routes on the provider kit. The generated <Key>ItemsController subclasses ProviderItemsController and only names its permitted params, and its routes use the provider_items concern. The 298-line controller scaffold goes (decided 2026-11-15: templates the kit owns are deleted outright).
Part of #5003 (Track B, step 6: the generator onto the kit, sliced by layer: B6a models, B6b account flow, B6c controller and routes, then views).
Stacked on #5263. Fork pre-flight: jaysbeekay/sure#756 (same branch, same commit; its CI, Gatekeeper review and screenshot history live there).
Before / after (what rails g provider:family writes)
| Before | After | |
|---|---|---|
app/controllers/<key>_items_controller.rb | 298-line ApplicationController scaffold with its own CRUD, selection, linking and setup | < ProviderItemsController, defining only item_params |
| A blank secret on an edit | overwrote the stored secret | dropped from the params, keeping the stored secret (as Brex, Mercury and Lunch Flow do) |
| Routes | a 15-line resources … do collection … member … end block, added at the top of the draw block by Rails' route helper | resources :<key>_items, only: %i[index new create show edit update destroy], concerns: :provider_items, inserted straight after the concern's definition |
Routes when config/routes.rb has no provider_items concern | not added; the generator says what to add | |
| Locale | the old controller's keys (no_api_key, sync.success, preload_accounts.*) | every message ProviderItemsController and ProviderItem::AccountFlow read: default_connection_name, select_connection, no_api_token, unexpected_error, the setup-completion messages |
The route helpers and paths are the ones the old block produced: the test compares the generated provider's named routes with Brex's, name for name.
Screenshots
None: no UI change.
Demo data
No demo data needed.
Migration notes
No migration.
Verification
- Tests, fail-first. Three tests replace the two that pinned the old scaffold's frame-redirect and panel behaviour. All three failed on the old templates (the old controller template could not render without
table_name; the old routes were not after the concern,Expected: 1; nogocardless_items.default_connection_name) and pass after:- "the generated controller is a thin provider kit controller": loads the rendered controller in an isolated namespace; checks it subclasses
ProviderItemsController, defines no action of its own, permits the declared fields and nothing else, drops a blank secret on an edit and keeps it on a create; - "the generated routes use the provider_items concern after it is defined": runs
add_routeson a copy ofconfig/routes.rb, checks the one inserted line sits after the concern, then draws the concern and that line in a freshRouteSetand compares its named routes with Brex's; - "the generated locale has every message the provider kit's controller and account flow read": 48 keys, each with Brex's plural forms and interpolations.
- "the generated locale names every setup option the account flow reads for a supported type" (added after full review 6947517022, finding 2): for each type the generated adapter supports,
setup_accounts.account_types,subtype_labelsand, where the flow shows one,subtype_messages. Droppingsubtype_labels.depository,subtype_messages.credit_cardorsubtype_labels.investmentfrom the template fails it.
- "the generated controller is a thin provider kit controller": loads the rendered controller in an isolated namespace; checks it subclasses
- A test ordering fix found on the way: routes load lazily in test, so the route test calls
Rails.application.reload_routes_unless_loadedbefore reading Brex's routes; without it, seed 6 failed. The file then passed on seeds 1–8. - Mutations, each caught (9): a blank secret overwriting on edit; a blank secret dropped on create too; a declared field not permitted; the controller defining its own action; the routes inserted at the top of the block; the routes without the concern;
default_connection_namemissing;no_api_tokenleft asno_api_key; an interpolation dropped frompartial_skipped. bin/rails test(full, at this commit): 16,531 runs, 0 failures; the same 8ReleaseNotesWorkflowTesterrors (nonodein the test image).bin/rubocopon the changed Ruby,bin/brakeman: no offenses or warnings.- Size (
git diff -C): non-test +48 / -328. - The earlier merge-down commits' subjects ("Merge up/... into up/...") exceed 72 characters. They stay fork-only: Track B is rebased linear when it goes upstream, as Track A was, so they never reach we-promise/sure.
- Checked against upstream AGENTS.md (blob 1a5dbebd, 2026-11-17): no deviations.
Blast radius
- Only
rails g provider:family. Existing providers andconfig/routes.rbare untouched. - What the kit's controller does differently from the old scaffold, for a newly generated provider: a new connection redirects to
/accountsand starts a sync (the scaffold went to Settings > Providers);select_*with no credentials render the kit's setup-required dialog rather than a frame redirect; selection, linking and setup go through the stubbed account flow from B6b, so they raiseNotImplementedErroruntil its hooks are written. - Siblings: the generated views still use the old templates and the old
panel.*keys; the next slices move them onto the kit's components. - Not runnable at this head on its own. The views generated here do not match the kit's controller yet:
setup_accounts.html.erbreads@unlinked_accounts, which the kit never sets, so every generated setup page raises; the setup form postsselected_accounts[]whilecomplete_account_setupreadsaccount_types;select_existing_accountreads@<key>_accountswhile the kit sets@available_accounts, so it always shows the empty state; and the kit rendersselect_accounts,_setup_requiredand_api_error, which this slice does not write. B6d (jaysbeekay/sure#757) writes every view the kit renders on the kit's components; this slice and B6d go upstream together in the one Track B stack, never apart (full review 6947517022, finding 1).
Summary by cubic
provider:family now generates a thin provider kit controller instead of a 298-line scaffold. The generated <Key>ItemsController subclasses ProviderItemsController, defines only its permitted item_params, and drops a blank secret on an edit so it keeps the stored value. Routes use the provider_items concern and are inserted right after its definition; if config/routes.rb has no such concern, the generator prints what to add instead of writing invalid routes. The generated locale gains every message the kit's controller and account flow read, with Brex's plural forms and interpolations; the old no_api_key and sync.success keys go.
For newly generated providers, a new connection redirects to /accounts and starts a sync instead of going to Settings > Providers, and selection, linking, and setup go through the stubbed account flow, raising NotImplementedError until its hooks are written.
Not runnable at this head
The generated views still use the old templates and don't match the kit's controller: setup_accounts.html.erb reads @unlinked_accounts, which the kit never sets, and select_existing_account reads @<key>_accounts while the kit sets @available_accounts. The next slice writes every view the kit renders; this slice and that one go upstream together.
Verification
- Five tests replace the two that pinned the old scaffold's redirects and panel behavior, all failing on the old templates and passing after: the thin controller, an end-to-end edit through the account flow, routes placed after the concern and matching Brex's named routes, the locale's kit-read keys matched against Brex, and the setup option labels per supported account type.
- The edit test expects a new key to expire the cached account list and a blank-key rename not to.
- 9 mutations caught, including blank-secret overwriting, the controller defining its own action, routes inserted at the top of the block, and missing locale keys.
bin/rails test: 16,531 runs, 0 failures.bin/rubocopandbin/brakemanclean.