The personal finance app for everyone (by everyone)
Ruby
Fix Disconnect and saves in Bank sync connection rows (#3844)
Guillem Arias Fausteab39cb205dfd
diff --git a/app/components/trade_republic/connection_card_component.html.erb b/app/components/trade_republic/connection_card_component.html.erbindex 283c6b0c5b..c2f7166337 100644--- a/app/components/trade_republic/connection_card_component.html.erb+++ b/app/components/trade_republic/connection_card_component.html.erb@@ -41,7 +41,7 @@variant: :outline,size: :sm,icon: "refresh-cw",- href: helpers.sync_trade_republic_item_path(item),+ href: helpers.sync_trade_republic_item_path(item, source: "panel"),method: :post,disabled: item.syncing?) %>diff --git a/app/components/trading212/account_editor_component.html.erb b/app/components/trading212/account_editor_component.html.erbindex d43355fee5..b64ebaa520 100644--- a/app/components/trading212/account_editor_component.html.erb+++ b/app/components/trading212/account_editor_component.html.erb@@ -21,7 +21,7 @@text: translation("sync"),icon: "refresh-cw",variant: :outline,- href: helpers.sync_trading212_item_path(item),+ href: helpers.sync_trading212_item_path(item, source: "panel"),method: :post,disabled: item.syncing?) %>diff --git a/app/controllers/akahu_items_controller.rb b/app/controllers/akahu_items_controller.rbindex 51d8edad95..6cfbd8c9da 100644--- a/app/controllers/akahu_items_controller.rb+++ b/app/controllers/akahu_items_controller.rb@@ -27,17 +27,17 @@ class AkahuItemsController < ApplicationControllerif @akahu_item.save@akahu_item.sync_later- render_provider_panel(:notice, t(".success"))+ redirect_to settings_providers_path, notice: t(".success"), status: :see_otherelse- render_provider_panel_error(@akahu_item.errors.full_messages.join(", "))+ render_provider_panel("akahu", alert: @akahu_item.errors.full_messages.join(", "))endenddef updateif @akahu_item.update(update_params)- render_provider_panel(:notice, t(".success"))+ render_provider_panel("akahu", notice: t(".success"))else- render_provider_panel_error(@akahu_item.errors.full_messages.join(", "))+ render_provider_panel("akahu", alert: @akahu_item.errors.full_messages.join(", "))endend@@ -52,6 +52,7 @@ class AkahuItemsController < ApplicationControllerdef sync@akahu_item.sync_later unless @akahu_item.syncing?+ return render_provider_panel("akahu", notice: t("settings.providers.sync_provider_in_progress")) if provider_panel_form?respond_to do |format|format.html { redirect_back_or_to accounts_path }@@ -305,36 +306,6 @@ class AkahuItemsController < ApplicationController)end- def render_provider_panel(flash_type, message)- if turbo_frame_request?- flash.now[flash_type] = message- @akahu_items = Current.family.akahu_items.active.ordered- render turbo_stream: [- turbo_stream.replace(- "akahu-providers-panel",- partial: "settings/providers/akahu_panel",- locals: { akahu_items: @akahu_items }- ),- *flash_notification_stream_items- ]- else- redirect_to settings_providers_path, { flash_type => message, status: :see_other }- end- end-- def render_provider_panel_error(message)- @error_message = message- if turbo_frame_request?- render turbo_stream: turbo_stream.replace(- "akahu-providers-panel",- partial: "settings/providers/akahu_panel",- locals: { error_message: @error_message }- ), status: :unprocessable_entity- else- redirect_to settings_providers_path, alert: @error_message, status: :unprocessable_entity- end- end-def safe_return_to_pathreturn nil if params[:return_to].blank?diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rbindex b36f281b77..65ed5888bf 100644--- a/app/controllers/application_controller.rb+++ b/app/controllers/application_controller.rb@@ -53,6 +53,36 @@ class ApplicationController < ActionController::Baseendend+ # Provider panels post from the page (connection row or drawer), so Turbo+ # asks for a stream without sending a Turbo-Frame header.+ def turbo_panel_request?+ turbo_frame_request? || request.format.turbo_stream?+ end++ # Set by a panel form whose action also serves another page with the same+ # Turbo request, such as a Sync that the Accounts page posts to as well.+ def provider_panel_form?+ params[:source] == "panel"+ end++ # Re-renders a Bank sync panel where it was posted from, with the alert in+ # the panel or the notice as a flash. `key` is the panel's FAMILY_PANELS key.+ # A request without Turbo is redirected with the flash instead.+ def render_provider_panel(key, notice: nil, alert: nil, fallback_path: settings_providers_path, **locals)+ return redirect_to(fallback_path, notice: notice, alert: alert, status: :see_other) unless turbo_panel_request?++ panel = Settings::ProvidersController::FAMILY_PANELS_BY_KEY.fetch(key)+ flash.now[:notice] = notice if notice+ render turbo_stream: [+ turbo_stream.replace(+ "#{panel[:turbo_id]}-providers-panel",+ partial: "settings/providers/#{panel[:partial]}",+ locals: { error_message: alert, **locals }+ ),+ *flash_notification_stream_items+ ], status: alert ? :unprocessable_entity : :ok+ end+def detect_osuser_agent = request.user_agent@os = case user_agentdiff --git a/app/controllers/binance_items_controller.rb b/app/controllers/binance_items_controller.rbindex 35562e68c3..c391678602 100644--- a/app/controllers/binance_items_controller.rb+++ b/app/controllers/binance_items_controller.rb@@ -26,63 +26,18 @@ class BinanceItemsController < ApplicationController@binance_item.set_binance_institution_defaults!@binance_item.sync_later- if turbo_frame_request?- flash.now[:notice] = t(".success")- @binance_items = Current.family.binance_items.ordered- render turbo_stream: [- turbo_stream.update(- "binance-providers-panel",- partial: "settings/providers/binance_panel",- locals: { binance_items: @binance_items }- ),- *flash_notification_stream_items- ]- else- redirect_to settings_providers_path, notice: t(".success"), status: :see_other- end+ redirect_to settings_providers_path, notice: t(".success"), status: :see_otherelse- @error_message = @binance_item.errors.full_messages.join(", ")-- if turbo_frame_request?- render turbo_stream: turbo_stream.replace(- "binance-providers-panel",- partial: "settings/providers/binance_panel",- locals: { error_message: @error_message }- ), status: :unprocessable_entity- else- redirect_to settings_providers_path, alert: @error_message, status: :see_other- end+ render_provider_panel("binance", alert: @binance_item.errors.full_messages.join(", "))endend+ # The panel has no edit form, so an update never re-renders it.def updateif @binance_item.update(binance_item_params)- if turbo_frame_request?- flash.now[:notice] = t(".success")- @binance_items = Current.family.binance_items.ordered- render turbo_stream: [- turbo_stream.update(- "binance-providers-panel",- partial: "settings/providers/binance_panel",- locals: { binance_items: @binance_items }- ),- *flash_notification_stream_items- ]- else- redirect_to settings_providers_path, notice: t(".success"), status: :see_other- end+ redirect_to settings_providers_path, notice: t(".success"), status: :see_otherelse- @error_message = @binance_item.errors.full_messages.join(", ")-- if turbo_frame_request?- render turbo_stream: turbo_stream.replace(- "binance-providers-panel",- partial: "settings/providers/binance_panel",- locals: { error_message: @error_message }- ), status: :unprocessable_entity- else- redirect_to settings_providers_path, alert: @error_message, status: :see_other- end+ redirect_to settings_providers_path, alert: @binance_item.errors.full_messages.join(", "), status: :see_otherendend@@ -95,6 +50,7 @@ class BinanceItemsController < ApplicationControllerunless @binance_item.syncing?@binance_item.sync_laterend+ return render_provider_panel("binance", notice: t("settings.providers.sync_provider_in_progress")) if provider_panel_form?respond_to do |format|format.html { redirect_back_or_to accounts_path }diff --git a/app/controllers/brex_items_controller.rb b/app/controllers/brex_items_controller.rbindex 551a36c47c..112008b18c 100644--- a/app/controllers/brex_items_controller.rb+++ b/app/controllers/brex_items_controller.rb@@ -20,9 +20,9 @@ class BrexItemsController < ApplicationControllerif @brex_item.save@brex_item.sync_later- render_provider_panel_success(t(".success"))+ redirect_to accounts_path, notice: t(".success"), status: :see_otherelse- render_provider_panel_error+ render_provider_panel("brex", alert: @brex_item.errors.full_messages.join(", "))endend@@ -31,9 +31,10 @@ class BrexItemsController < ApplicationControllerdef updateif BrexItem::AccountFlow.update_item_with_cache_expiration(@brex_item, family: Current.family, attributes: brex_item_params)- render_provider_panel_success(t(".success"))+ render_provider_panel("brex", notice: t(".success"), fallback_path: accounts_path,+ brex_items: Current.family.brex_items.active.ordered.includes(:syncs, :brex_accounts))else- render_provider_panel_error+ render_provider_panel("brex", alert: @brex_item.errors.full_messages.join(", "))endend@@ -45,6 +46,7 @@ class BrexItemsController < ApplicationControllerdef sync@brex_item.sync_later unless @brex_item.syncing?+ return render_provider_panel("brex", notice: t("settings.providers.sync_provider_in_progress")) if provider_panel_form?respond_to do |format|format.html { redirect_back_or_to accounts_path }@@ -54,33 +56,6 @@ class BrexItemsController < ApplicationControllerprivate- def render_provider_panel_success(message)- return redirect_to accounts_path, notice: message, status: :see_other unless turbo_frame_request?-- flash.now[:notice] = message- @brex_items = Current.family.brex_items.active.ordered.includes(:syncs, :brex_accounts)- render_brex_provider_panel(locals: { brex_items: @brex_items }, include_flash: true)- end-- def render_provider_panel_error- @error_message = @brex_item.errors.full_messages.join(", ")- return redirect_to settings_providers_path, alert: @error_message, status: :see_other unless turbo_frame_request?-- render_brex_provider_panel(locals: { error_message: @error_message }, status: :unprocessable_entity)- end-- def render_brex_provider_panel(locals:, status: :ok, include_flash: false)- streams = [- turbo_stream.replace(- "brex-providers-panel",- partial: "settings/providers/brex_panel",- locals: locals- )- ]- streams += flash_notification_stream_items if include_flash- render turbo_stream: streams, status: status- end-def set_brex_item@brex_item = Current.family.brex_items.find(params[:id])enddiff --git a/app/controllers/coinbase_items_controller.rb b/app/controllers/coinbase_items_controller.rbindex 498853574c..7c23edc7bf 100644--- a/app/controllers/coinbase_items_controller.rb+++ b/app/controllers/coinbase_items_controller.rb@@ -27,63 +27,18 @@ class CoinbaseItemsController < ApplicationController# Trigger initial sync to fetch accounts@coinbase_item.sync_later- if turbo_frame_request?- flash.now[:notice] = t(".success")- @coinbase_items = Current.family.coinbase_items.ordered- render turbo_stream: [- turbo_stream.replace(- "coinbase-providers-panel",- partial: "settings/providers/coinbase_panel",- locals: { coinbase_items: @coinbase_items }- ),- *flash_notification_stream_items- ]- else- redirect_to settings_providers_path, notice: t(".success"), status: :see_other- end+ redirect_to settings_providers_path, notice: t(".success"), status: :see_otherelse- @error_message = @coinbase_item.errors.full_messages.join(", ")-- if turbo_frame_request?- render turbo_stream: turbo_stream.replace(- "coinbase-providers-panel",- partial: "settings/providers/coinbase_panel",- locals: { error_message: @error_message }- ), status: :unprocessable_entity- else- redirect_to settings_providers_path, alert: @error_message, status: :unprocessable_entity- end+ render_provider_panel("coinbase", alert: @coinbase_item.errors.full_messages.join(", "))endend+ # The panel has no edit form, so an update never re-renders it.def updateif @coinbase_item.update(coinbase_item_params)- if turbo_frame_request?- flash.now[:notice] = t(".success")- @coinbase_items = Current.family.coinbase_items.ordered- render turbo_stream: [- turbo_stream.replace(- "coinbase-providers-panel",- partial: "settings/providers/coinbase_panel",- locals: { coinbase_items: @coinbase_items }- ),- *flash_notification_stream_items- ]- else- redirect_to settings_providers_path, notice: t(".success"), status: :see_other- end+ redirect_to settings_providers_path, notice: t(".success"), status: :see_otherelse- @error_message = @coinbase_item.errors.full_messages.join(", ")-- if turbo_frame_request?- render turbo_stream: turbo_stream.replace(- "coinbase-providers-panel",- partial: "settings/providers/coinbase_panel",- locals: { error_message: @error_message }- ), status: :unprocessable_entity- else- redirect_to settings_providers_path, alert: @error_message, status: :unprocessable_entity- end+ redirect_to settings_providers_path, alert: @coinbase_item.errors.full_messages.join(", "), status: :see_otherendend@@ -96,6 +51,7 @@ class CoinbaseItemsController < ApplicationControllerunless @coinbase_item.syncing?@coinbase_item.sync_laterend+ return render_provider_panel("coinbase", notice: t("settings.providers.sync_provider_in_progress")) if provider_panel_form?respond_to do |format|format.html { redirect_back_or_to accounts_path }diff --git a/app/controllers/coinspot_items_controller.rb b/app/controllers/coinspot_items_controller.rbindex f833d8481a..6b9e35a05c 100644--- a/app/controllers/coinspot_items_controller.rb+++ b/app/controllers/coinspot_items_controller.rb@@ -16,9 +16,9 @@ class CoinspotItemsController < ApplicationControllerif @coinspot_item.save@coinspot_item.set_coinspot_institution_defaults!@coinspot_item.sync_later- render_panel_success(t(".success"))+ redirect_to settings_providers_path, notice: t(".success"), status: :see_otherelse- render_panel_error(@coinspot_item.errors.full_messages.join(", "))+ render_provider_panel("coinspot", alert: @coinspot_item.errors.full_messages.join(", "))endend@@ -26,9 +26,9 @@ class CoinspotItemsController < ApplicationController# optionally new credentials).def updateif @coinspot_item.update(coinspot_item_params)- render_panel_success(t(".success"))+ render_provider_panel("coinspot", notice: t(".success"))else- render_panel_error(@coinspot_item.errors.full_messages.join(", "))+ render_provider_panel("coinspot", alert: @coinspot_item.errors.full_messages.join(", "))endend@@ -52,6 +52,7 @@ class CoinspotItemsController < ApplicationController# Queues a manual sync, unless one is already running.def sync@coinspot_item.sync_later unless @coinspot_item.syncing?+ return render_provider_panel("coinspot", notice: t("settings.providers.sync_provider_in_progress")) if provider_panel_form?respond_to do |format|format.html { redirect_back_or_to settings_providers_path }@@ -251,38 +252,6 @@ class CoinspotItemsController < ApplicationControllerpermittedend- # Reports a settings-panel action's success: a Turbo Stream update for a- # frame request, or a full-page redirect otherwise.- def render_panel_success(message)- if turbo_frame_request?- flash.now[:notice] = message- @coinspot_items = Current.family.coinspot_items.active.ordered- stream = turbo_stream.update(- "coinspot-providers-panel",- partial: "settings/providers/coinspot_panel",- locals: { coinspot_items: @coinspot_items }- )- render turbo_stream: [ stream, *flash_notification_stream_items ]- else- redirect_to settings_providers_path, notice: message, status: :see_other- end- end-- # Reports a settings-panel action's failure: a Turbo Stream replace for a- # frame request, or a full-page redirect with an alert otherwise.- def render_panel_error(message)- if turbo_frame_request?- @coinspot_items = Current.family.coinspot_items.active.ordered- render turbo_stream: turbo_stream.replace(- "coinspot-providers-panel",- partial: "settings/providers/coinspot_panel",- locals: { error_message: message }- ), status: :unprocessable_entity- else- redirect_to settings_providers_path, alert: message, status: :see_other- end- end-# Resolves which connection an account-linking flow should act on: the# one named by params[:coinspot_item_id], or the family's only# credentialed connection when there's exactly one and no id was given.diff --git a/app/controllers/coinstats_items_controller.rb b/app/controllers/coinstats_items_controller.rbindex 37c28860a2..2dd32e59dd 100644--- a/app/controllers/coinstats_items_controller.rb+++ b/app/controllers/coinstats_items_controller.rb@@ -22,13 +22,13 @@ class CoinstatsItemsController < ApplicationController# Validate API key before savingunless validate_api_key(@coinstats_item.api_key)- return render_error_response(@coinstats_item.errors.full_messages.join(", "))+ return render_provider_panel("coinstats", alert: @coinstats_item.errors.full_messages.join(", "))endif @coinstats_item.save- render_success_response(".success")+ redirect_to settings_providers_path, notice: t(".success"), status: :see_otherelse- render_error_response(@coinstats_item.errors.full_messages.join(", "))+ render_provider_panel("coinstats", alert: @coinstats_item.errors.full_messages.join(", "))endend@@ -38,13 +38,13 @@ class CoinstatsItemsController < ApplicationControllerdef update# Validate API key if it's being changedunless validate_api_key(coinstats_item_params[:api_key])- return render_error_response(@coinstats_item.errors.full_messages.join(", "))+ return render_provider_panel("coinstats", alert: @coinstats_item.errors.full_messages.join(", "))endif @coinstats_item.update(coinstats_item_params)- render_success_response(".success")+ render_provider_panel("coinstats", notice: t(".success"))else- render_error_response(@coinstats_item.errors.full_messages.join(", "))+ render_provider_panel("coinstats", alert: @coinstats_item.errors.full_messages.join(", "))endend@@ -165,35 +165,6 @@ class CoinstatsItemsController < ApplicationControllerfalseend- def render_error_response(error_message)- if turbo_frame_request?- render turbo_stream: turbo_stream.replace(- "coinstats-providers-panel",- partial: "settings/providers/coinstats_panel",- locals: { error_message: error_message }- ), status: :unprocessable_entity- else- redirect_to settings_providers_path, alert: error_message, status: :unprocessable_entity- end- end-- def render_success_response(notice_key)- if turbo_frame_request?- flash.now[:notice] = t(notice_key, default: notice_key.to_s.humanize)- @coinstats_items = Current.family.coinstats_items.ordered- render turbo_stream: [- turbo_stream.replace(- "coinstats-providers-panel",- partial: "settings/providers/coinstats_panel",- locals: { coinstats_items: @coinstats_items }- ),- *flash_notification_stream_items- ]- else- redirect_to settings_providers_path, notice: t(notice_key), status: :see_other- end- end-def render_link_wallet_error(error_message)@error_message = error_messageprepare_link_form_statediff --git a/app/controllers/enable_banking_items_controller.rb b/app/controllers/enable_banking_items_controller.rbindex 901d0589cf..041af65c27 100644--- a/app/controllers/enable_banking_items_controller.rb+++ b/app/controllers/enable_banking_items_controller.rb@@ -13,63 +13,17 @@ class EnableBankingItemsController < ApplicationController@enable_banking_item.name ||= "Enable Banking Connection"if @enable_banking_item.save- if turbo_frame_request?- flash.now[:notice] = t(".success", default: "Successfully configured Enable Banking.")- @enable_banking_items = Current.family.enable_banking_items.ordered- render turbo_stream: [- turbo_stream.replace(- "enable_banking-providers-panel",- partial: "settings/providers/enable_banking_panel",- locals: { enable_banking_items: @enable_banking_items }- ),- *flash_notification_stream_items- ]- else- redirect_to settings_providers_path, notice: t(".success"), status: :see_other- end+ redirect_to settings_providers_path, notice: t(".success"), status: :see_otherelse- @error_message = @enable_banking_item.errors.full_messages.join(", ")-- if turbo_frame_request?- render turbo_stream: turbo_stream.replace(- "enable_banking-providers-panel",- partial: "settings/providers/enable_banking_panel",- locals: { error_message: @error_message }- ), status: :unprocessable_entity- else- redirect_to settings_providers_path, alert: @error_message, status: :unprocessable_entity- end+ render_provider_panel("enable_banking", alert: @enable_banking_item.errors.full_messages.join(", "))endenddef updateif @enable_banking_item.update(enable_banking_item_params)- if turbo_frame_request?- flash.now[:notice] = t(".success", default: "Successfully updated Enable Banking configuration.")- @enable_banking_items = Current.family.enable_banking_items.ordered- render turbo_stream: [- turbo_stream.replace(- "enable_banking-providers-panel",- partial: "settings/providers/enable_banking_panel",- locals: { enable_banking_items: @enable_banking_items }- ),- *flash_notification_stream_items- ]- else- redirect_to settings_providers_path, notice: t(".success"), status: :see_other- end+ render_provider_panel("enable_banking", notice: t(".success"), enable_banking_items: Current.family.enable_banking_items.ordered)else- @error_message = @enable_banking_item.errors.full_messages.join(", ")-- if turbo_frame_request?- render turbo_stream: turbo_stream.replace(- "enable_banking-providers-panel",- partial: "settings/providers/enable_banking_panel",- locals: { error_message: @error_message }- ), status: :unprocessable_entity- else- redirect_to settings_providers_path, alert: @error_message, status: :unprocessable_entity- end+ render_provider_panel("enable_banking", alert: @enable_banking_item.errors.full_messages.join(", "))endend@@ -89,6 +43,10 @@ class EnableBankingItemsController < ApplicationControllerunless @enable_banking_item.syncing?@enable_banking_item.sync_laterend+ if provider_panel_form?+ return render_provider_panel("enable_banking", notice: t("settings.providers.sync_provider_in_progress"),+ enable_banking_items: Current.family.enable_banking_items.ordered)+ endrespond_to do |format|format.html { redirect_back_or_to accounts_path }diff --git a/app/controllers/fio_items_controller.rb b/app/controllers/fio_items_controller.rbindex b5f2c46259..4316cebd81 100644--- a/app/controllers/fio_items_controller.rb+++ b/app/controllers/fio_items_controller.rb@@ -22,7 +22,7 @@ class FioItemsController < ApplicationControllertoken = attributes[:token].to_s.stripif token.blank?- render_provider_panel_error(t(".token_required"))+ render_provider_panel("fio", alert: t(".token_required"))returnend@@ -32,9 +32,9 @@ class FioItemsController < ApplicationControllersync_start_date: attributes[:sync_start_date].presence)- render_provider_panel(:notice, t(".success"))+ redirect_to settings_providers_path, notice: t(".success"), status: :see_otherrescue ActiveRecord::RecordInvalid => e- render_provider_panel_error(e.record.errors.full_messages.join(", "))+ render_provider_panel("fio", alert: e.record.errors.full_messages.join(", "))end# Rotate the token and/or rename the connection and/or move its sync start date.@@ -53,9 +53,9 @@ class FioItemsController < ApplicationController# sync can find out whether Fio still accepts it. Without this the connection sits# marked healthy until the next scheduled run.@fio_item.sync_later unless @fio_item.syncing?- render_provider_panel(:notice, t(".success"))+ render_provider_panel("fio", notice: t(".success"))else- render_provider_panel_error(@fio_item.errors.full_messages.join(", "))+ render_provider_panel("fio", alert: @fio_item.errors.full_messages.join(", "))endend@@ -100,6 +100,7 @@ class FioItemsController < ApplicationControllerdef sync@fio_item.update!(history_unlock_required_at: nil) if @fio_item.history_unlock_required_at.present?@fio_item.sync_later unless @fio_item.syncing?+ return render_provider_panel("fio", notice: t("settings.providers.sync_provider_in_progress")) if provider_panel_form?respond_to do |format|format.html { redirect_back_or_to accounts_path }@@ -359,38 +360,6 @@ class FioItemsController < ApplicationController)end- # Re-render the providers settings panel (Turbo) or redirect with a flash.- def render_provider_panel(flash_type, message)- if turbo_frame_request?- flash.now[flash_type] = message- @fio_items = Current.family.fio_items.active.ordered- render turbo_stream: [- turbo_stream.replace(- "fio-providers-panel",- partial: "settings/providers/fio_panel",- locals: { fio_items: @fio_items }- ),- *flash_notification_stream_items- ]- else- redirect_to settings_providers_path, { flash_type => message, status: :see_other }- end- end-- # Re-render the providers panel with an error (Turbo) or redirect with alert.- def render_provider_panel_error(message)- @error_message = message- if turbo_frame_request?- render turbo_stream: turbo_stream.replace(- "fio-providers-panel",- partial: "settings/providers/fio_panel",- locals: { error_message: @error_message }- ), status: :unprocessable_entity- else- redirect_to settings_providers_path, alert: @error_message, status: :see_other- end- end-# Validate the return_to param as a safe in-app relative path, or nil.def safe_return_to_pathreturn nil if params[:return_to].blank?diff --git a/app/controllers/ibkr_items_controller.rb b/app/controllers/ibkr_items_controller.rbindex 34936995bb..4579f44e20 100644--- a/app/controllers/ibkr_items_controller.rb+++ b/app/controllers/ibkr_items_controller.rb@@ -9,30 +9,9 @@ class IbkrItemsController < ApplicationControllerif @ibkr_item.save@ibkr_item.sync_later- if turbo_frame_request?- flash.now[:notice] = t(".success")- render turbo_stream: [- turbo_stream.replace(- "ibkr-providers-panel",- partial: "settings/providers/ibkr_panel"- ),- *flash_notification_stream_items- ]- else- redirect_to accounts_path, notice: t(".success"), status: :see_other- end+ redirect_to accounts_path, notice: t(".success"), status: :see_otherelse- @error_message = @ibkr_item.errors.full_messages.join(", ")-- if turbo_frame_request?- render turbo_stream: turbo_stream.replace(- "ibkr-providers-panel",- partial: "settings/providers/ibkr_panel",- locals: { error_message: @error_message }- ), status: :unprocessable_entity- else- redirect_to settings_providers_path, alert: @error_message, status: :see_other- end+ render_provider_panel("ibkr", alert: @ibkr_item.errors.full_messages.join(", "))endend@@ -44,30 +23,9 @@ class IbkrItemsController < ApplicationControllerif @ibkr_item.update(attrs.merge(status: :good))@ibkr_item.sync_later unless @ibkr_item.syncing?- if turbo_frame_request?- flash.now[:notice] = t(".success")- render turbo_stream: [- turbo_stream.replace(- "ibkr-providers-panel",- partial: "settings/providers/ibkr_panel"- ),- *flash_notification_stream_items- ]- else- redirect_to accounts_path, notice: t(".success"), status: :see_other- end+ render_provider_panel("ibkr", notice: t(".success"), fallback_path: accounts_path)else- @error_message = @ibkr_item.errors.full_messages.join(", ")-- if turbo_frame_request?- render turbo_stream: turbo_stream.replace(- "ibkr-providers-panel",- partial: "settings/providers/ibkr_panel",- locals: { error_message: @error_message }- ), status: :unprocessable_entity- else- redirect_to settings_providers_path, alert: @error_message, status: :see_other- end+ render_provider_panel("ibkr", alert: @ibkr_item.errors.full_messages.join(", "))endend@@ -84,6 +42,7 @@ class IbkrItemsController < ApplicationControllerdef sync@ibkr_item.sync_later unless @ibkr_item.syncing?+ return render_provider_panel("ibkr", notice: t("settings.providers.sync_provider_in_progress")) if provider_panel_form?respond_to do |format|format.html { redirect_back_or_to accounts_path }diff --git a/app/controllers/indexa_capital_items_controller.rb b/app/controllers/indexa_capital_items_controller.rbindex d5872528b5..8649ff39b2 100644--- a/app/controllers/indexa_capital_items_controller.rb+++ b/app/controllers/indexa_capital_items_controller.rb@@ -25,63 +25,17 @@ class IndexaCapitalItemsController < ApplicationController@indexa_capital_item.name ||= "IndexaCapital Connection"if @indexa_capital_item.save- if turbo_frame_request?- flash.now[:notice] = t(".success", default: "Successfully configured IndexaCapital.")- @indexa_capital_items = Current.family.indexa_capital_items.ordered- render turbo_stream: [- turbo_stream.replace(- "indexa_capital-providers-panel",- partial: "settings/providers/indexa_capital_panel",- locals: { indexa_capital_items: @indexa_capital_items }- ),- *flash_notification_stream_items- ]- else- redirect_to settings_providers_path, notice: t(".success"), status: :see_other- end+ redirect_to settings_providers_path, notice: t(".success"), status: :see_otherelse- @error_message = @indexa_capital_item.errors.full_messages.join(", ")-- if turbo_frame_request?- render turbo_stream: turbo_stream.replace(- "indexa_capital-providers-panel",- partial: "settings/providers/indexa_capital_panel",- locals: { error_message: @error_message }- ), status: :unprocessable_entity- else- redirect_to settings_providers_path, alert: @error_message, status: :unprocessable_entity- end+ render_provider_panel("indexa_capital", alert: @indexa_capital_item.errors.full_messages.join(", "))endenddef updateif @indexa_capital_item.update(indexa_capital_item_params)- if turbo_frame_request?- flash.now[:notice] = t(".success", default: "Successfully updated IndexaCapital configuration.")- @indexa_capital_items = Current.family.indexa_capital_items.ordered- render turbo_stream: [- turbo_stream.replace(- "indexa_capital-providers-panel",- partial: "settings/providers/indexa_capital_panel",- locals: { indexa_capital_items: @indexa_capital_items }- ),- *flash_notification_stream_items- ]- else- redirect_to settings_providers_path, notice: t(".success"), status: :see_other- end+ render_provider_panel("indexa_capital", notice: t(".success"))else- @error_message = @indexa_capital_item.errors.full_messages.join(", ")-- if turbo_frame_request?- render turbo_stream: turbo_stream.replace(- "indexa_capital-providers-panel",- partial: "settings/providers/indexa_capital_panel",- locals: { error_message: @error_message }- ), status: :unprocessable_entity- else- redirect_to settings_providers_path, alert: @error_message, status: :unprocessable_entity- end+ render_provider_panel("indexa_capital", alert: @indexa_capital_item.errors.full_messages.join(", "))endenddiff --git a/app/controllers/kraken_items_controller.rb b/app/controllers/kraken_items_controller.rbindex 6daba850f1..08f8064bd7 100644--- a/app/controllers/kraken_items_controller.rb+++ b/app/controllers/kraken_items_controller.rb@@ -11,17 +11,17 @@ class KrakenItemsController < ApplicationControllerif @kraken_item.save@kraken_item.set_kraken_institution_defaults!@kraken_item.sync_later- render_panel_success(t(".success"))+ redirect_to settings_providers_path, notice: t(".success"), status: :see_otherelse- render_panel_error(@kraken_item.errors.full_messages.join(", "))+ render_provider_panel("kraken", alert: @kraken_item.errors.full_messages.join(", "))endenddef updateif @kraken_item.update(kraken_item_params)- render_panel_success(t(".success"))+ render_provider_panel("kraken", notice: t(".success"))else- render_panel_error(@kraken_item.errors.full_messages.join(", "))+ render_provider_panel("kraken", alert: @kraken_item.errors.full_messages.join(", "))endend@@ -33,6 +33,7 @@ class KrakenItemsController < ApplicationControllerdef sync@kraken_item.sync_later unless @kraken_item.syncing?+ return render_provider_panel("kraken", notice: t("settings.providers.sync_provider_in_progress")) if provider_panel_form?respond_to do |format|format.html { redirect_back_or_to settings_providers_path }@@ -166,29 +167,6 @@ class KrakenItemsController < ApplicationControllerpermittedend- def render_panel_success(message)- if turbo_frame_request?- flash.now[:notice] = message- @kraken_items = Current.family.kraken_items.active.ordered- stream = turbo_stream.update("kraken-providers-panel", partial: "settings/providers/kraken_panel", locals: { kraken_items: @kraken_items })- render turbo_stream: [ stream, *flash_notification_stream_items ]- else- redirect_to settings_providers_path, notice: message, status: :see_other- end- end-- def render_panel_error(message)- if turbo_frame_request?- render turbo_stream: turbo_stream.replace(- "kraken-providers-panel",- partial: "settings/providers/kraken_panel",- locals: { error_message: message }- ), status: :unprocessable_entity- else- redirect_to settings_providers_path, alert: message, status: :see_other- end- end-def kraken_item_account_flow_contextcredentialed_items = Current.family.kraken_items.active.credentials_configured.ordered.select(&:credentials_configured?)item = if params[:kraken_item_id].present?diff --git a/app/controllers/lunchflow_items_controller.rb b/app/controllers/lunchflow_items_controller.rbindex cfbc8feb5c..ca58dde0ed 100644--- a/app/controllers/lunchflow_items_controller.rb+++ b/app/controllers/lunchflow_items_controller.rb@@ -417,32 +417,9 @@ class LunchflowItemsController < ApplicationController# Trigger initial sync to fetch accounts@lunchflow_item.sync_later- if turbo_frame_request?- flash.now[:notice] = t(".success")- @lunchflow_items = Current.family.lunchflow_items.ordered- render turbo_stream: [- turbo_stream.replace(- "lunchflow-providers-panel",- partial: "settings/providers/lunchflow_panel",- locals: { lunchflow_items: @lunchflow_items }- ),- *flash_notification_stream_items- ]- else- redirect_to accounts_path, notice: t(".success"), status: :see_other- end+ redirect_to accounts_path, notice: t(".success"), status: :see_otherelse- @error_message = @lunchflow_item.errors.full_messages.join(", ")-- if turbo_frame_request?- render turbo_stream: turbo_stream.replace(- "lunchflow-providers-panel",- partial: "settings/providers/lunchflow_panel",- locals: { error_message: @error_message }- ), status: :unprocessable_entity- else- redirect_back_or_to accounts_path, alert: @error_message- end+ render_provider_panel("lunchflow", alert: @lunchflow_item.errors.full_messages.join(", "))endend@@ -451,32 +428,9 @@ class LunchflowItemsController < ApplicationControllerdef updateif @lunchflow_item.update(lunchflow_params)- if turbo_frame_request?- flash.now[:notice] = t(".success")- @lunchflow_items = Current.family.lunchflow_items.ordered- render turbo_stream: [- turbo_stream.replace(- "lunchflow-providers-panel",- partial: "settings/providers/lunchflow_panel",- locals: { lunchflow_items: @lunchflow_items }- ),- *flash_notification_stream_items- ]- else- redirect_to accounts_path, notice: t(".success"), status: :see_other- end+ render_provider_panel("lunchflow", notice: t(".success"), fallback_path: accounts_path)else- @error_message = @lunchflow_item.errors.full_messages.join(", ")-- if turbo_frame_request?- render turbo_stream: turbo_stream.replace(- "lunchflow-providers-panel",- partial: "settings/providers/lunchflow_panel",- locals: { error_message: @error_message }- ), status: :unprocessable_entity- else- render :edit, status: :unprocessable_entity- end+ render_provider_panel("lunchflow", alert: @lunchflow_item.errors.full_messages.join(", "))endenddiff --git a/app/controllers/mercury_items_controller.rb b/app/controllers/mercury_items_controller.rbindex f971caec57..653d733fea 100644--- a/app/controllers/mercury_items_controller.rb+++ b/app/controllers/mercury_items_controller.rb@@ -410,32 +410,9 @@ class MercuryItemsController < ApplicationController# Trigger initial sync to fetch accounts@mercury_item.sync_later- if turbo_frame_request?- flash.now[:notice] = t(".success")- @mercury_items = Current.family.mercury_items.active.ordered.includes(:syncs, :mercury_accounts)- render turbo_stream: [- turbo_stream.replace(- "mercury-providers-panel",- partial: "settings/providers/mercury_panel",- locals: { mercury_items: @mercury_items }- ),- *flash_notification_stream_items- ]- else- redirect_to accounts_path, notice: t(".success"), status: :see_other- end+ redirect_to accounts_path, notice: t(".success"), status: :see_otherelse- @error_message = @mercury_item.errors.full_messages.join(", ")-- if turbo_frame_request?- render turbo_stream: turbo_stream.replace(- "mercury-providers-panel",- partial: "settings/providers/mercury_panel",- locals: { error_message: @error_message }- ), status: :unprocessable_entity- else- render :new, status: :unprocessable_entity- end+ render_provider_panel("mercury", alert: @mercury_item.errors.full_messages.join(", "))endend@@ -449,32 +426,10 @@ class MercuryItemsController < ApplicationControllerif @mercury_item.update(permitted_params)Rails.cache.delete(mercury_accounts_cache_key(@mercury_item)) if expire_accounts_cache- if turbo_frame_request?- flash.now[:notice] = t(".success")- @mercury_items = Current.family.mercury_items.active.ordered.includes(:syncs, :mercury_accounts)- render turbo_stream: [- turbo_stream.replace(- "mercury-providers-panel",- partial: "settings/providers/mercury_panel",- locals: { mercury_items: @mercury_items }- ),- *flash_notification_stream_items- ]- else- redirect_to accounts_path, notice: t(".success"), status: :see_other- end+ render_provider_panel("mercury", notice: t(".success"), fallback_path: accounts_path,+ mercury_items: Current.family.mercury_items.active.ordered.includes(:syncs, :mercury_accounts))else- @error_message = @mercury_item.errors.full_messages.join(", ")-- if turbo_frame_request?- render turbo_stream: turbo_stream.replace(- "mercury-providers-panel",- partial: "settings/providers/mercury_panel",- locals: { error_message: @error_message }- ), status: :unprocessable_entity- else- render :edit, status: :unprocessable_entity- end+ render_provider_panel("mercury", alert: @mercury_item.errors.full_messages.join(", "))endend@@ -493,6 +448,7 @@ class MercuryItemsController < ApplicationControllerunless @mercury_item.syncing?@mercury_item.sync_laterend+ return render_provider_panel("mercury", notice: t("settings.providers.sync_provider_in_progress")) if provider_panel_form?respond_to do |format|format.html { redirect_back_or_to accounts_path }diff --git a/app/controllers/monobank_items_controller.rb b/app/controllers/monobank_items_controller.rbindex b001016718..21b2c8fa99 100644--- a/app/controllers/monobank_items_controller.rb+++ b/app/controllers/monobank_items_controller.rb@@ -17,18 +17,18 @@ class MonobankItemsController < ApplicationControllerif @monobank_item.save@monobank_item.sync_later- render_provider_panel(:notice, t(".success"))+ redirect_to settings_providers_path, notice: t(".success"), status: :see_otherelse- render_provider_panel_error(@monobank_item.errors.full_messages.join(", "))+ render_provider_panel("monobank", alert: @monobank_item.errors.full_messages.join(", "))endend# Update connection settings (name/token/start date).def updateif @monobank_item.update(update_params)- render_provider_panel(:notice, t(".success"))+ render_provider_panel("monobank", notice: t(".success"))else- render_provider_panel_error(@monobank_item.errors.full_messages.join(", "))+ render_provider_panel("monobank", alert: @monobank_item.errors.full_messages.join(", "))endend@@ -68,6 +68,7 @@ class MonobankItemsController < ApplicationController# Trigger a manual sync unless one is already running.def sync@monobank_item.sync_later unless @monobank_item.syncing?+ return render_provider_panel("monobank", notice: t("settings.providers.sync_provider_in_progress")) if provider_panel_form?respond_to do |format|format.html { redirect_back_or_to accounts_path }@@ -364,38 +365,6 @@ class MonobankItemsController < ApplicationController)end- # Re-render the providers settings panel (Turbo) or redirect with a flash.- def render_provider_panel(flash_type, message)- if turbo_frame_request?- flash.now[flash_type] = message- @monobank_items = Current.family.monobank_items.active.ordered- render turbo_stream: [- turbo_stream.replace(- "monobank-providers-panel",- partial: "settings/providers/monobank_panel",- locals: { monobank_items: @monobank_items }- ),- *flash_notification_stream_items- ]- else- redirect_to settings_providers_path, { flash_type => message, status: :see_other }- end- end-- # Re-render the providers panel with an error (Turbo) or redirect with alert.- def render_provider_panel_error(message)- @error_message = message- if turbo_frame_request?- render turbo_stream: turbo_stream.replace(- "monobank-providers-panel",- partial: "settings/providers/monobank_panel",- locals: { error_message: @error_message }- ), status: :unprocessable_entity- else- redirect_to settings_providers_path, alert: @error_message, status: :see_other- end- end-# Validate the return_to param as a safe in-app relative path, or nil.def safe_return_to_pathreturn nil if params[:return_to].blank?diff --git a/app/controllers/onchain_wallet_items_controller.rb b/app/controllers/onchain_wallet_items_controller.rbindex c5821fcdd4..14b63f5191 100644--- a/app/controllers/onchain_wallet_items_controller.rb+++ b/app/controllers/onchain_wallet_items_controller.rb@@ -12,9 +12,9 @@ class OnchainWalletItemsController < ApplicationControllerdef updateif @onchain_wallet_item.update(onchain_wallet_item_params)- render_panel_success(t(".success"))+ render_provider_panel("onchain_wallet", notice: t(".success"))else- render_panel_error(@onchain_wallet_item.errors.full_messages.join(", "))+ render_provider_panel("onchain_wallet", alert: @onchain_wallet_item.errors.full_messages.join(", "))endend@@ -262,33 +262,4 @@ class OnchainWalletItemsController < ApplicationController@error_message = error_messagerender :new_wallet, status: statusend-- def render_panel_success(message)- if turbo_frame_request?- flash.now[:notice] = message- @onchain_wallet_items = Current.family.onchain_wallet_items.active.ordered- render turbo_stream: [- turbo_stream.update(- "onchain_wallet-providers-panel",- partial: "settings/providers/onchain_wallet_panel",- locals: { onchain_wallet_items: @onchain_wallet_items }- ),- *flash_notification_stream_items- ]- else- redirect_to settings_providers_path, notice: message, status: :see_other- end- end-- def render_panel_error(message)- if turbo_frame_request?- render turbo_stream: turbo_stream.update(- "onchain_wallet-providers-panel",- partial: "settings/providers/onchain_wallet_panel",- locals: { error_message: message }- ), status: :unprocessable_entity- else- redirect_to settings_providers_path, alert: message, status: :see_other- end- endenddiff --git a/app/controllers/questrade_items_controller.rb b/app/controllers/questrade_items_controller.rbindex 5289cec5d1..5fd4572fa0 100644--- a/app/controllers/questrade_items_controller.rb+++ b/app/controllers/questrade_items_controller.rb@@ -29,32 +29,9 @@ class QuestradeItemsController < ApplicationController# Accounts tab for setup.@questrade_item.sync_later unless @questrade_item.syncing?- if turbo_frame_request?- flash.now[:notice] = t(".success", default: "Successfully configured Questrade.")- @questrade_items = Current.family.questrade_items.ordered- render turbo_stream: [- turbo_stream.replace(- "questrade-providers-panel",- partial: "settings/providers/questrade_panel",- locals: { questrade_items: @questrade_items }- ),- *flash_notification_stream_items- ]- else- redirect_to settings_providers_path, notice: t(".success"), status: :see_other- end+ redirect_to settings_providers_path, notice: t(".success"), status: :see_otherelse- @error_message = @questrade_item.errors.full_messages.join(", ")-- if turbo_frame_request?- render turbo_stream: turbo_stream.replace(- "questrade-providers-panel",- partial: "settings/providers/questrade_panel",- locals: { error_message: @error_message }- ), status: :unprocessable_entity- else- redirect_to settings_providers_path, alert: @error_message- end+ render_provider_panel("questrade", alert: @questrade_item.errors.full_messages.join(", "))endend@@ -64,32 +41,9 @@ class QuestradeItemsController < ApplicationControllerupdate_attrs = update_attrs.merge(status: :good) if update_attrs[:refresh_token].present?if @questrade_item.update(update_attrs)- if turbo_frame_request?- flash.now[:notice] = t(".success", default: "Successfully updated Questrade configuration.")- @questrade_items = Current.family.questrade_items.ordered- render turbo_stream: [- turbo_stream.replace(- "questrade-providers-panel",- partial: "settings/providers/questrade_panel",- locals: { questrade_items: @questrade_items }- ),- *flash_notification_stream_items- ]- else- redirect_to settings_providers_path, notice: t(".success"), status: :see_other- end+ render_provider_panel("questrade", notice: t(".success"), questrade_items: Current.family.questrade_items.ordered)else- @error_message = @questrade_item.errors.full_messages.join(", ")-- if turbo_frame_request?- render turbo_stream: turbo_stream.replace(- "questrade-providers-panel",- partial: "settings/providers/questrade_panel",- locals: { error_message: @error_message }- ), status: :unprocessable_entity- else- redirect_to settings_providers_path, alert: @error_message- end+ render_provider_panel("questrade", alert: @questrade_item.errors.full_messages.join(", "))endenddiff --git a/app/controllers/redbark_items_controller.rb b/app/controllers/redbark_items_controller.rbindex 1f095ba9c1..fbb5f86f3b 100644--- a/app/controllers/redbark_items_controller.rb+++ b/app/controllers/redbark_items_controller.rb@@ -14,30 +14,9 @@ class RedbarkItemsController < ApplicationController# Trigger the initial sync so accounts appear without a manual refresh@redbark_item.sync_later- if turbo_frame_request?- flash.now[:notice] = t(".success")- render turbo_stream: [- turbo_stream.replace(- "redbark-providers-panel",- partial: "settings/providers/redbark_panel"- ),- *flash_notification_stream_items- ]- else- redirect_to settings_providers_path, notice: t(".success"), status: :see_other- end+ redirect_to settings_providers_path, notice: t(".success"), status: :see_otherelse- @error_message = @redbark_item.errors.full_messages.join(", ")-- if turbo_frame_request?- render turbo_stream: turbo_stream.replace(- "redbark-providers-panel",- partial: "settings/providers/redbark_panel",- locals: { error_message: @error_message }- ), status: :unprocessable_entity- else- redirect_to settings_providers_path, alert: @error_message, status: :see_other- end+ render_provider_panel("redbark", alert: @redbark_item.errors.full_messages.join(", "))endend@@ -50,30 +29,9 @@ class RedbarkItemsController < ApplicationController# Rotated credentials should be exercised right away@redbark_item.sync_later if update_params[:api_key].present? && !@redbark_item.syncing?- if turbo_frame_request?- flash.now[:notice] = t(".success")- render turbo_stream: [- turbo_stream.replace(- "redbark-providers-panel",- partial: "settings/providers/redbark_panel"- ),- *flash_notification_stream_items- ]- else- redirect_to settings_providers_path, notice: t(".success"), status: :see_other- end+ render_provider_panel("redbark", notice: t(".success"))else- @error_message = @redbark_item.errors.full_messages.join(", ")-- if turbo_frame_request?- render turbo_stream: turbo_stream.replace(- "redbark-providers-panel",- partial: "settings/providers/redbark_panel",- locals: { error_message: @error_message }- ), status: :unprocessable_entity- else- redirect_to settings_providers_path, alert: @error_message, status: :see_other- end+ render_provider_panel("redbark", alert: @redbark_item.errors.full_messages.join(", "))endenddiff --git a/app/controllers/settings/providers_controller.rb b/app/controllers/settings/providers_controller.rbindex a0d1fbb48e..c70225121b 100644--- a/app/controllers/settings/providers_controller.rb+++ b/app/controllers/settings/providers_controller.rb@@ -111,6 +111,8 @@ class Settings::ProvidersController < ApplicationControllerdef connect_formprovider_key = params[:provider_key]+ # Not FAMILY_PANELS_BY_KEY[provider_key]: Brakeman reads that as the param+ # choosing the partial to render.panel = FAMILY_PANELS.find { |p| p[:key] == provider_key }if panel@panel_key = panel[:key]@@ -215,6 +217,7 @@ class Settings::ProvidersController < ApplicationController].freezeFAMILY_PANEL_KEYS = FAMILY_PANELS.map { |p| p[:key] }.freeze+ FAMILY_PANELS_BY_KEY = FAMILY_PANELS.index_by { |p| p[:key] }.freeze# Maps panel key → ActiveRecord model name for sync health queriesPANEL_SYNCABLE_TYPES = {diff --git a/app/controllers/simplefin_items_controller.rb b/app/controllers/simplefin_items_controller.rbindex 836f7e10fe..7007fd4408 100644--- a/app/controllers/simplefin_items_controller.rb+++ b/app/controllers/simplefin_items_controller.rb@@ -71,20 +71,7 @@ class SimplefinItemsController < ApplicationControlleritem_name: "SimpleFIN Connection")- if turbo_frame_request?- flash.now[:notice] = t(".success")- @simplefin_items = Current.family.simplefin_items.ordered- render turbo_stream: [- turbo_stream.replace(- "simplefin-providers-panel",- partial: "settings/providers/simplefin_panel",- locals: { simplefin_items: @simplefin_items }- ),- *flash_notification_stream_items- ]- else- redirect_to accounts_path, notice: t(".success"), status: :see_other- end+ redirect_to accounts_path, notice: t(".success"), status: :see_otherrescue ArgumentError, URI::InvalidURIErrorrender_error(t(".errors.invalid_token"), setup_token)rescue Provider::Simplefin::SimplefinError => e@@ -547,14 +534,11 @@ class SimplefinItemsController < ApplicationControllerend@error_message = message- if turbo_frame_request?- # Re-render the SimpleFIN providers panel in place to avoid "Content missing"- @simplefin_items = Current.family.simplefin_items.ordered- render turbo_stream: turbo_stream.replace(- "simplefin-providers-panel",- partial: "settings/providers/simplefin_panel",- locals: { simplefin_items: @simplefin_items }- ), status: :unprocessable_entity+ # The Bank sync panel and the new-connection modal send the same Turbo+ # request, so the panel marks its form. The modals render their template,+ # which the edit modal's frame picks out of the response.+ if provider_panel_form?+ render_provider_panel("simplefin", alert: message)elserender context, status: :unprocessable_entityenddiff --git a/app/controllers/sophtron_items_controller.rb b/app/controllers/sophtron_items_controller.rbindex 6222954efb..9735cbbdd4 100644--- a/app/controllers/sophtron_items_controller.rb+++ b/app/controllers/sophtron_items_controller.rb@@ -394,13 +394,13 @@ class SophtronItemsController < ApplicationControllerif @sophtron_item.saveunless verify_and_provision_customer(@sophtron_item)- render_sophtron_panel_error(:new, @sophtron_item.last_connection_error)+ render_provider_panel("sophtron", alert: @sophtron_item.last_connection_error)returnend- render_sophtron_panel_success(:create)+ redirect_to accounts_path, notice: t(".success"), status: :see_otherelse- render_sophtron_panel_error(:new, @sophtron_item.errors.full_messages.join(", "))+ render_provider_panel("sophtron", alert: @sophtron_item.errors.full_messages.join(", "))endend@@ -410,13 +410,13 @@ class SophtronItemsController < ApplicationControllerdef updateif @sophtron_item.update(sophtron_params)unless verify_and_provision_customer(@sophtron_item)- render_sophtron_panel_error(:edit, @sophtron_item.last_connection_error)+ render_provider_panel("sophtron", alert: @sophtron_item.last_connection_error)returnend- render_sophtron_panel_success(:update)+ render_provider_panel("sophtron", notice: t(".success"), fallback_path: accounts_path)else- render_sophtron_panel_error(:edit, @sophtron_item.errors.full_messages.join(", "))+ render_provider_panel("sophtron", alert: @sophtron_item.errors.full_messages.join(", "))endend@@ -944,36 +944,6 @@ class SophtronItemsController < ApplicationControllerfalseend- def render_sophtron_panel_success(action_name)- if turbo_frame_request?- flash.now[:notice] = t("sophtron_items.#{action_name}.success")- @sophtron_items = Current.family.sophtron_items.ordered- render turbo_stream: [- turbo_stream.replace(- "sophtron-providers-panel",- partial: "settings/providers/sophtron_panel",- locals: { sophtron_items: @sophtron_items }- ),- *flash_notification_stream_items- ]- else- redirect_to accounts_path, notice: t("sophtron_items.#{action_name}.success"), status: :see_other- end- end-- def render_sophtron_panel_error(view_name, message)- @error_message = message- if turbo_frame_request?- render turbo_stream: turbo_stream.replace(- "sophtron-providers-panel",- partial: "settings/providers/sophtron_panel",- locals: { error_message: @error_message }- ), status: :unprocessable_entity- else- render view_name, status: :unprocessable_entity- end- end-def render_or_redirect_setup_requiredif turbo_frame_request?render partial: "sophtron_items/setup_required", layout: falsediff --git a/app/controllers/trade_republic_items_controller.rb b/app/controllers/trade_republic_items_controller.rbindex 4c97dddf8e..30b3c56d4b 100644--- a/app/controllers/trade_republic_items_controller.rb+++ b/app/controllers/trade_republic_items_controller.rb@@ -320,6 +320,10 @@ class TradeRepublicItemsController < ApplicationControllerdef sync@trade_republic_item.sync_later unless @trade_republic_item.syncing?+ if provider_panel_form? && turbo_panel_request?+ # Only this card, as the login steps do, so the other cards keep their state.+ return render_login_panel(notice: t("settings.providers.sync_provider_in_progress"))+ endrespond_to do |format|format.html { redirect_back_or_to accounts_path }@@ -643,28 +647,11 @@ class TradeRepublicItemsController < ApplicationController@trade_republic_item.destroy_later if @trade_republic_item.trade_republic_accounts.none?end- def turbo_panel_request?- turbo_frame_request? || request.format.turbo_stream?- end-+ # Only the add-connection form's own unsaved item should replace its blank+ # default; an existing item failing update/login keeps the add form blank.def render_panel_error(message)- @error_message = message-- if turbo_panel_request?- render turbo_stream: turbo_stream.replace(- "trade-republic-providers-panel",- partial: "settings/providers/trade_republic_panel",- locals: {- error_message: @error_message,- # Only the add-connection form's own unsaved item should replace- # its blank default; an existing item failing update/login keeps- # the add form blank.- new_item: (@trade_republic_item if @trade_republic_item&.new_record?)- }- ), status: :unprocessable_entity- else- redirect_to settings_providers_path(anchor: "trade-republic"), alert: @error_message, status: :see_other- end+ render_provider_panel("trade_republic", alert: message, fallback_path: settings_providers_path(anchor: "trade-republic"),+ new_item: (@trade_republic_item if @trade_republic_item&.new_record?))enddef render_qr_login_error(error, pending: nil, status: :unprocessable_entity, retryable: false)diff --git a/app/controllers/trading212_items_controller.rb b/app/controllers/trading212_items_controller.rbindex db7a41d815..f05a604797 100644--- a/app/controllers/trading212_items_controller.rb+++ b/app/controllers/trading212_items_controller.rb@@ -10,30 +10,9 @@ class Trading212ItemsController < ApplicationControllerif @trading212_item.save@trading212_item.sync_later- if turbo_frame_request?- flash.now[:notice] = t(".success")- render turbo_stream: [- turbo_stream.replace(- "trading212-providers-panel",- partial: "settings/providers/trading212_panel"- ),- *flash_notification_stream_items- ]- else- redirect_to accounts_path, notice: t(".success"), status: :see_other- end+ redirect_to accounts_path, notice: t(".success"), status: :see_otherelse- @error_message = @trading212_item.errors.full_messages.join(", ")-- if turbo_frame_request?- render turbo_stream: turbo_stream.replace(- "trading212-providers-panel",- partial: "settings/providers/trading212_panel",- locals: { error_message: @error_message }- ), status: :unprocessable_entity- else- redirect_to settings_providers_path, alert: @error_message, status: :see_other- end+ render_provider_panel("trading212", alert: @trading212_item.errors.full_messages.join(", "))endend@@ -45,30 +24,9 @@ class Trading212ItemsController < ApplicationControllerif @trading212_item.update(attrs.merge(status: :good))@trading212_item.sync_later unless @trading212_item.syncing?- if turbo_frame_request?- flash.now[:notice] = t(".success")- render turbo_stream: [- turbo_stream.replace(- "trading212-providers-panel",- partial: "settings/providers/trading212_panel"- ),- *flash_notification_stream_items- ]- else- redirect_to accounts_path, notice: t(".success"), status: :see_other- end+ render_provider_panel("trading212", notice: t(".success"), fallback_path: accounts_path)else- @error_message = @trading212_item.errors.full_messages.join(", ")-- if turbo_frame_request?- render turbo_stream: turbo_stream.replace(- "trading212-providers-panel",- partial: "settings/providers/trading212_panel",- locals: { error_message: @error_message }- ), status: :unprocessable_entity- else- redirect_to settings_providers_path, alert: @error_message, status: :see_other- end+ render_provider_panel("trading212", alert: @trading212_item.errors.full_messages.join(", "))endend@@ -80,6 +38,7 @@ class Trading212ItemsController < ApplicationControllerdef sync@trading212_item.sync_later unless @trading212_item.syncing?+ return render_provider_panel("trading212", notice: t("settings.providers.sync_provider_in_progress")) if provider_panel_form?respond_to do |format|format.html { redirect_back_or_to accounts_path }diff --git a/app/controllers/up_items_controller.rb b/app/controllers/up_items_controller.rbindex 19998bd1c4..310c855a79 100644--- a/app/controllers/up_items_controller.rb+++ b/app/controllers/up_items_controller.rb@@ -32,18 +32,18 @@ class UpItemsController < ApplicationControllerif @up_item.save@up_item.sync_later- render_provider_panel(:notice, t(".success"))+ redirect_to settings_providers_path, notice: t(".success"), status: :see_otherelse- render_provider_panel_error(@up_item.errors.full_messages.join(", "))+ render_provider_panel("up", alert: @up_item.errors.full_messages.join(", "))endend# Update connection settings (name/token/start date).def updateif @up_item.update(update_params)- render_provider_panel(:notice, t(".success"))+ render_provider_panel("up", notice: t(".success"))else- render_provider_panel_error(@up_item.errors.full_messages.join(", "))+ render_provider_panel("up", alert: @up_item.errors.full_messages.join(", "))endend@@ -83,6 +83,7 @@ class UpItemsController < ApplicationController# Trigger a manual sync unless one is already running.def sync@up_item.sync_later unless @up_item.syncing?+ return render_provider_panel("up", notice: t("settings.providers.sync_provider_in_progress")) if provider_panel_form?respond_to do |format|format.html { redirect_back_or_to accounts_path }@@ -376,38 +377,6 @@ class UpItemsController < ApplicationController)end- # Re-render the providers settings panel (Turbo) or redirect with a flash.- def render_provider_panel(flash_type, message)- if turbo_frame_request?- flash.now[flash_type] = message- @up_items = Current.family.up_items.active.ordered- render turbo_stream: [- turbo_stream.replace(- "up-providers-panel",- partial: "settings/providers/up_panel",- locals: { up_items: @up_items }- ),- *flash_notification_stream_items- ]- else- redirect_to settings_providers_path, { flash_type => message, status: :see_other }- end- end-- # Re-render the providers panel with an error (Turbo) or redirect with alert.- def render_provider_panel_error(message)- @error_message = message- if turbo_frame_request?- render turbo_stream: turbo_stream.replace(- "up-providers-panel",- partial: "settings/providers/up_panel",- locals: { error_message: @error_message }- ), status: :unprocessable_entity- else- redirect_to settings_providers_path, alert: @error_message, status: :see_other- end- end-# Validate the return_to param as a safe in-app relative path, or nil.def safe_return_to_pathreturn nil if params[:return_to].blank?diff --git a/app/controllers/wise_items_controller.rb b/app/controllers/wise_items_controller.rbindex 7963f5eca1..be0f316c72 100644--- a/app/controllers/wise_items_controller.rb+++ b/app/controllers/wise_items_controller.rb@@ -125,6 +125,7 @@ class WiseItemsController < ApplicationControllerdef sync@wise_item.sync_later unless @wise_item.syncing?+ return render_provider_panel("wise", notice: t("settings.providers.sync_provider_in_progress")) if provider_panel_form?respond_to do |format|format.html { redirect_back_or_to accounts_path }@@ -281,30 +282,12 @@ class WiseItemsController < ApplicationControllerenddef render_provider_panel_success(message)- return redirect_to accounts_path, notice: message, status: :see_other unless turbo_frame_request?-- flash.now[:notice] = message- @wise_items = Current.family.wise_items.active.ordered.includes(:syncs, :wise_accounts)- render_wise_provider_panel(locals: { wise_items: @wise_items }, include_flash: true)+ render_provider_panel("wise", notice: message, fallback_path: accounts_path,+ wise_items: Current.family.wise_items.active.ordered.includes(:syncs, :wise_accounts))enddef render_provider_panel_error- @error_message = @wise_item.errors.full_messages.join(", ")- return redirect_to settings_providers_path, alert: @error_message, status: :see_other unless turbo_frame_request?-- render_wise_provider_panel(locals: { error_message: @error_message }, status: :unprocessable_entity)- end-- def render_wise_provider_panel(locals:, status: :ok, include_flash: false)- streams = [- turbo_stream.replace(- "wise-providers-panel",- partial: "settings/providers/wise_panel",- locals: locals- )- ]- streams += flash_notification_stream_items if include_flash- render turbo_stream: streams, status: status+ render_provider_panel("wise", alert: @wise_item.errors.full_messages.join(", "))enddef encrypt_pending_token(token)diff --git a/app/views/settings/providers/_akahu_panel.html.erb b/app/views/settings/providers/_akahu_panel.html.erbindex da3189e927..42ab448229 100644--- a/app/views/settings/providers/_akahu_panel.html.erb+++ b/app/views/settings/providers/_akahu_panel.html.erb@@ -36,7 +36,7 @@icon: "refresh-cw",variant: :outline,size: :sm,- href: sync_akahu_item_path(item),+ href: sync_akahu_item_path(item, source: "panel"),method: :post,disabled: item.syncing?) %>diff --git a/app/views/settings/providers/_binance_panel.html.erb b/app/views/settings/providers/_binance_panel.html.erbindex cba8907de0..775104c0fc 100644--- a/app/views/settings/providers/_binance_panel.html.erb+++ b/app/views/settings/providers/_binance_panel.html.erb@@ -1,4 +1,4 @@-<div class="space-y-4">+<div id="binance-providers-panel" class="space-y-4"><% items = local_assigns[:binance_items] || @binance_items || Current.family.binance_items.active.ordered %><%= render DS::Alert.new(@@ -66,7 +66,7 @@icon: "refresh-cw",variant: :outline,size: :sm,- href: sync_binance_item_path(item),+ href: sync_binance_item_path(item, source: "panel"),method: :post,disabled: item.syncing?) %>diff --git a/app/views/settings/providers/_brex_panel.html.erb b/app/views/settings/providers/_brex_panel.html.erbindex e96e32265c..a01c02b03d 100644--- a/app/views/settings/providers/_brex_panel.html.erb+++ b/app/views/settings/providers/_brex_panel.html.erb@@ -37,7 +37,7 @@icon: "refresh-cw",variant: :outline,size: :sm,- href: sync_brex_item_path(item),+ href: sync_brex_item_path(item, source: "panel"),method: :post,disabled: item.syncing?) %>diff --git a/app/views/settings/providers/_coinbase_panel.html.erb b/app/views/settings/providers/_coinbase_panel.html.erbindex 9f7a89de8e..4e11545b3f 100644--- a/app/views/settings/providers/_coinbase_panel.html.erb+++ b/app/views/settings/providers/_coinbase_panel.html.erb@@ -36,7 +36,7 @@icon: "refresh-cw",variant: :outline,size: :sm,- href: sync_coinbase_item_path(item),+ href: sync_coinbase_item_path(item, source: "panel"),method: :post,disabled: item.syncing?) %>diff --git a/app/views/settings/providers/_coinspot_panel.html.erb b/app/views/settings/providers/_coinspot_panel.html.erbindex 9034958850..0766087d91 100644--- a/app/views/settings/providers/_coinspot_panel.html.erb+++ b/app/views/settings/providers/_coinspot_panel.html.erb@@ -1,5 +1,5 @@<div id="coinspot-providers-panel" class="space-y-4">- <% items = local_assigns[:coinspot_items] || @coinspot_items %>+ <% items = local_assigns[:coinspot_items] || @coinspot_items || Current.family.coinspot_items.active.ordered %><%= render DS::Alert.new(variant: :warning,@@ -48,7 +48,7 @@icon: "refresh-cw",variant: :outline,size: :sm,- href: sync_coinspot_item_path(item),+ href: sync_coinspot_item_path(item, source: "panel"),method: :post,disabled: item.syncing?) %>diff --git a/app/views/settings/providers/_coinstats_panel.html.erb b/app/views/settings/providers/_coinstats_panel.html.erbindex d545c99522..4352db196e 100644--- a/app/views/settings/providers/_coinstats_panel.html.erb+++ b/app/views/settings/providers/_coinstats_panel.html.erb@@ -1,4 +1,4 @@-<div class="space-y-4">+<div id="coinstats-providers-panel" class="space-y-4"><%= render "settings/providers/setup_steps",steps: [t("coinstats_items.new.step1_html").html_safe,diff --git a/app/views/settings/providers/_connection_row.html.erb b/app/views/settings/providers/_connection_row.html.erbindex 16b088ac2a..7a813f0b52 100644--- a/app/views/settings/providers/_connection_row.html.erb+++ b/app/views/settings/providers/_connection_row.html.erb@@ -14,7 +14,8 @@maturity_lbl = Settings::ProviderCard.maturity_label(entry[:maturity])details_data = entry[:auto_open_param].present? ? { controller: "auto-open", auto_open_param_value: entry[:auto_open_param] } : {}%>-<%= tag.details open: open,+<%= tag.details id: ("#{entry[:turbo_id]}-connection" if entry[:turbo_id]),+ open: open,class: "group bg-container shadow-border-xs rounded-xl #{border_class}",data: details_data do %><summary class="min-h-15 px-4 py-3.5 cursor-pointer rounded-xl list-none [&::-webkit-details-marker]:hidden">@@ -44,9 +45,7 @@configuration: entry[:configuration],provider_setup_encryption_warning: provider_setup_encryption_warning %><% else %>- <turbo-frame id="<%= entry[:turbo_id] %>-providers-panel">- <%= render "settings/providers/#{entry[:partial]}" %>- </turbo-frame>+ <%= render "settings/providers/#{entry[:partial]}" %><% end %></div><% end %>diff --git a/app/views/settings/providers/_enable_banking_panel.html.erb b/app/views/settings/providers/_enable_banking_panel.html.erbindex d2370aba05..152bb102c5 100644--- a/app/views/settings/providers/_enable_banking_panel.html.erb+++ b/app/views/settings/providers/_enable_banking_panel.html.erb@@ -1,4 +1,4 @@-<div class="space-y-4">+<div id="enable_banking-providers-panel" class="space-y-4"><%eb_link = link_to("Enable Banking", "https://enablebanking.com", target: "_blank", rel: "noopener noreferrer", class: "text-link underline")%>@@ -148,10 +148,9 @@icon: "refresh-cw",variant: :outline,size: :sm,- href: sync_enable_banking_item_path(item),+ href: sync_enable_banking_item_path(item, source: "panel"),method: :post,- disabled: item.syncing?,- data: { turbo: false }+ disabled: item.syncing?) %><% elsif item.session_expired? %><%= render DS::Button.new(diff --git a/app/views/settings/providers/_financekit_panel.html.erb b/app/views/settings/providers/_financekit_panel.html.erbindex f9aa7b0454..782295e2cd 100644--- a/app/views/settings/providers/_financekit_panel.html.erb+++ b/app/views/settings/providers/_financekit_panel.html.erb@@ -25,7 +25,7 @@<ul class="space-y-2" aria-label="<%= t("settings.providers.financekit.accounts") %>"><% connection[:accounts].each do |account| %><li class="flex flex-wrap items-center justify-between gap-2 text-sm">- <%= link_to account.name, account_path(account), class: "text-primary underline", data: { turbo_frame: "_top" } %>+ <%= link_to account.name, account_path(account), class: "text-primary underline" %><span class="text-secondary"><%= format_money(account.balance_money) %></span></li><% end %>diff --git a/app/views/settings/providers/_fio_panel.html.erb b/app/views/settings/providers/_fio_panel.html.erbindex 1f92465264..21037d97f7 100644--- a/app/views/settings/providers/_fio_panel.html.erb+++ b/app/views/settings/providers/_fio_panel.html.erb@@ -69,7 +69,7 @@icon: "refresh-cw",variant: :outline,size: :sm,- href: sync_fio_item_path(item),+ href: sync_fio_item_path(item, source: "panel"),method: :post,disabled: item.syncing?) %>diff --git a/app/views/settings/providers/_ibkr_panel.html.erb b/app/views/settings/providers/_ibkr_panel.html.erbindex 2887bb5a28..44e0c7da96 100644--- a/app/views/settings/providers/_ibkr_panel.html.erb+++ b/app/views/settings/providers/_ibkr_panel.html.erb@@ -98,7 +98,7 @@<% if ibkr_item.persisted? %><div class="flex flex-wrap justify-end gap-2">- <%= button_to sync_ibkr_item_path(ibkr_item),+ <%= button_to sync_ibkr_item_path(ibkr_item, source: "panel"),method: :post,class: "inline-flex items-center gap-1 px-3 py-1.5 text-sm font-medium text-secondary hover:text-primary border border-secondary rounded-lg hover:border-primary",disabled: ibkr_item.syncing? do %>diff --git a/app/views/settings/providers/_indexa_capital_panel.html.erb b/app/views/settings/providers/_indexa_capital_panel.html.erbindex 255126e424..44602d1bbc 100644--- a/app/views/settings/providers/_indexa_capital_panel.html.erb+++ b/app/views/settings/providers/_indexa_capital_panel.html.erb@@ -1,4 +1,4 @@-<div class="space-y-4">+<div id="indexa_capital-providers-panel" class="space-y-4"><%= render "settings/providers/setup_steps",steps: [t("indexa_capital_items.panel.step_1"),diff --git a/app/views/settings/providers/_kraken_panel.html.erb b/app/views/settings/providers/_kraken_panel.html.erbindex 63e89847c7..1510307db8 100644--- a/app/views/settings/providers/_kraken_panel.html.erb+++ b/app/views/settings/providers/_kraken_panel.html.erb@@ -48,7 +48,7 @@icon: "refresh-cw",variant: :outline,size: :sm,- href: sync_kraken_item_path(item),+ href: sync_kraken_item_path(item, source: "panel"),method: :post,disabled: item.syncing?) %>diff --git a/app/views/settings/providers/_lunchflow_panel.html.erb b/app/views/settings/providers/_lunchflow_panel.html.erbindex a27c7573a5..0df02f4b9a 100644--- a/app/views/settings/providers/_lunchflow_panel.html.erb+++ b/app/views/settings/providers/_lunchflow_panel.html.erb@@ -1,4 +1,4 @@-<div class="space-y-4">+<div id="lunchflow-providers-panel" class="space-y-4"><%lf_link = link_to("Lunch Flow", "https://www.lunchflow.app/?atp=BiDIYS", target: "_blank", rel: "noopener noreferrer", class: "text-link underline")%>diff --git a/app/views/settings/providers/_mercury_panel.html.erb b/app/views/settings/providers/_mercury_panel.html.erbindex a4170e8bd3..1c76d27f2b 100644--- a/app/views/settings/providers/_mercury_panel.html.erb+++ b/app/views/settings/providers/_mercury_panel.html.erb@@ -38,7 +38,7 @@icon: "refresh-cw",variant: :outline,size: :sm,- href: sync_mercury_item_path(item),+ href: sync_mercury_item_path(item, source: "panel"),method: :post,disabled: item.syncing?) %>diff --git a/app/views/settings/providers/_monobank_panel.html.erb b/app/views/settings/providers/_monobank_panel.html.erbindex df4e68179d..60e7ffd370 100644--- a/app/views/settings/providers/_monobank_panel.html.erb+++ b/app/views/settings/providers/_monobank_panel.html.erb@@ -38,7 +38,7 @@icon: "refresh-cw",variant: :outline,size: :sm,- href: sync_monobank_item_path(item),+ href: sync_monobank_item_path(item, source: "panel"),method: :post,disabled: item.syncing?) %>diff --git a/app/views/settings/providers/_questrade_panel.html.erb b/app/views/settings/providers/_questrade_panel.html.erbindex 041924d038..982caeb9d0 100644--- a/app/views/settings/providers/_questrade_panel.html.erb+++ b/app/views/settings/providers/_questrade_panel.html.erb@@ -1,4 +1,4 @@-<div class="space-y-4">+<div id="questrade-providers-panel" class="space-y-4"><% items = local_assigns[:questrade_items] || @questrade_items || Current.family.questrade_items.where.not(refresh_token: nil) %><% connected = items.present? && items.any? %>@@ -56,7 +56,7 @@size: :sm,href: questrade_item_path(items.first),method: :delete,- data: { turbo_frame: "_top", turbo_confirm: t("questrade_items.panel.disconnect_confirm") }+ data: { turbo_confirm: t("questrade_items.panel.disconnect_confirm") }) %></div><% else %>diff --git a/app/views/settings/providers/_simplefin_panel.html.erb b/app/views/settings/providers/_simplefin_panel.html.erbindex d64fba0333..58bf2afb5c 100644--- a/app/views/settings/providers/_simplefin_panel.html.erb+++ b/app/views/settings/providers/_simplefin_panel.html.erb@@ -1,4 +1,4 @@-<div class="space-y-4">+<div id="simplefin-providers-panel" class="space-y-4"><%sf_link = link_to("SimpleFIN Bridge", "https://beta-bridge.simplefin.org", target: "_blank", rel: "noopener noreferrer", class: "text-link underline")%>@@ -9,8 +9,9 @@t("settings.providers.simplefin_panel.step_3")] %>- <% if defined?(@error_message) && @error_message.present? %>- <%= render DS::Alert.new(message: @error_message, variant: :error) %>+ <% error_msg = local_assigns[:error_message] || @error_message %>+ <% if error_msg.present? %>+ <%= render DS::Alert.new(message: error_msg, variant: :error) %><% end %><%= styled_form_with model: SimplefinItem.new,@@ -19,6 +20,8 @@method: :post,data: { turbo: true },class: "space-y-3" do |form| %>+ <%# The new-connection modal posts to the same action but shows errors in its own template. %>+ <%= hidden_field_tag :source, "panel" %><%= form.text_field :setup_token,label: t("settings.providers.simplefin_panel.setup_token_label"),placeholder: t("settings.providers.simplefin_panel.setup_token_placeholder"),diff --git a/app/views/settings/providers/_sophtron_panel.html.erb b/app/views/settings/providers/_sophtron_panel.html.erbindex 4511d01dc8..3a315d8bdf 100644--- a/app/views/settings/providers/_sophtron_panel.html.erb+++ b/app/views/settings/providers/_sophtron_panel.html.erb@@ -1,4 +1,4 @@-<div class="space-y-4">+<div id="sophtron-providers-panel" class="space-y-4"><%= render "settings/providers/setup_steps",steps: [t("sophtron_items.sophtron_panel.setup_instructions.step_1_html", url: "https://www.sophtron.com").html_safe,diff --git a/app/views/settings/providers/_up_panel.html.erb b/app/views/settings/providers/_up_panel.html.erbindex d0c03a0b79..49e82f2558 100644--- a/app/views/settings/providers/_up_panel.html.erb+++ b/app/views/settings/providers/_up_panel.html.erb@@ -36,7 +36,7 @@icon: "refresh-cw",variant: :outline,size: :sm,- href: sync_up_item_path(item),+ href: sync_up_item_path(item, source: "panel"),method: :post,disabled: item.syncing?) %>diff --git a/app/views/settings/providers/_wise_panel.html.erb b/app/views/settings/providers/_wise_panel.html.erbindex 69bcc2a18e..9651c6baab 100644--- a/app/views/settings/providers/_wise_panel.html.erb+++ b/app/views/settings/providers/_wise_panel.html.erb@@ -37,7 +37,7 @@icon: "refresh-cw",variant: :outline,size: :sm,- href: sync_wise_item_path(item),+ href: sync_wise_item_path(item, source: "panel"),method: :post,disabled: item.syncing?) %>diff --git a/docs/api/rails_provider_generator.md b/docs/api/rails_provider_generator.mdindex f274043c07..287c77285d 100644--- a/docs/api/rails_provider_generator.md+++ b/docs/api/rails_provider_generator.md@@ -84,7 +84,7 @@ This single command generates:- ✅ Simple manual panel view for provider settings- ✅ Controller with CRUD actions and Turbo Stream support- ✅ Routes-- ✅ Updates to settings controller and view+- ✅ Bank sync wiring: the settings controller's `FAMILY_PANELS` entry and sync maps, and a `provider_summary` caseThe generated item partial renders the provider's logo with `ProviderLogo`. That reads theprovider's `Provider::Metadata::REGISTRY` entry, which the generator does not create, so add@@ -397,10 +397,11 @@ end**File:** `app/views/settings/providers/_my_bank_panel.html.erb`-A simple manual form for configuring My Bank credentials:+A simple manual form for configuring My Bank credentials. The root id is what the+controller's Turbo Streams replace:```erb-<div class="space-y-4">+<div id="my_bank-providers-panel" class="space-y-4"><div class="prose prose-sm text-secondary"><p class="text-primary font-medium">Setup instructions:</p><ol>@@ -469,7 +470,10 @@ A simple manual form for configuring My Bank credentials:**File:** `app/controllers/my_bank_items_controller.rb`-A simple controller with CRUD actions and Turbo Stream support:+A simple controller with CRUD actions. The panel's forms post from the page (a+connection row or the drawer), and `render_provider_panel` answers their updates and+errors in place: it replaces the panel root named by the provider's `FAMILY_PANELS`+entry, or redirects when the request isn't from Turbo. A new connection reloads Bank sync:```rubyclass MyBankItemsController < ApplicationController@@ -480,63 +484,17 @@ class MyBankItemsController < ApplicationController@my_bank_item.name ||= "My Bank Connection"if @my_bank_item.save- if turbo_frame_request?- flash.now[:notice] = t(".success", default: "Successfully configured My Bank.")- @my_bank_items = Current.family.my_bank_items.ordered- render turbo_stream: [- turbo_stream.replace(- "my-bank-providers-panel",- partial: "settings/providers/my_bank_panel",- locals: { my_bank_items: @my_bank_items }- ),- *flash_notification_stream_items- ]- else- redirect_to settings_providers_path, notice: t(".success"), status: :see_other- end+ redirect_to settings_providers_path, notice: t(".success"), status: :see_otherelse- @error_message = @my_bank_item.errors.full_messages.join(", ")-- if turbo_frame_request?- render turbo_stream: turbo_stream.replace(- "my-bank-providers-panel",- partial: "settings/providers/my_bank_panel",- locals: { error_message: @error_message }- ), status: :unprocessable_entity- else- redirect_to settings_providers_path, alert: @error_message, status: :unprocessable_entity- end+ render_provider_panel("my_bank", alert: @my_bank_item.errors.full_messages.join(", "))endenddef updateif @my_bank_item.update(my_bank_item_params)- if turbo_frame_request?- flash.now[:notice] = t(".success", default: "Successfully updated My Bank configuration.")- @my_bank_items = Current.family.my_bank_items.ordered- render turbo_stream: [- turbo_stream.replace(- "my-bank-providers-panel",- partial: "settings/providers/my_bank_panel",- locals: { my_bank_items: @my_bank_items }- ),- *flash_notification_stream_items- ]- else- redirect_to settings_providers_path, notice: t(".success"), status: :see_other- end+ render_provider_panel("my_bank", notice: t(".success"))else- @error_message = @my_bank_item.errors.full_messages.join(", ")-- if turbo_frame_request?- render turbo_stream: turbo_stream.replace(- "my-bank-providers-panel",- partial: "settings/providers/my_bank_panel",- locals: { error_message: @error_message }- ), status: :unprocessable_entity- else- redirect_to settings_providers_path, alert: @error_message, status: :unprocessable_entity- end+ render_provider_panel("my_bank", alert: @my_bank_item.errors.full_messages.join(", "))endend@@ -589,11 +547,15 @@ end### 7. Settings Updates**File:** `app/controllers/settings/providers_controller.rb` (updated)-- Excludes `my_bank` from global provider configurations- Adds `@my_bank_items` instance variable+- Adds a `FAMILY_PANELS` entry, so Bank sync lists My Bank and opens its panel in the+ drawer. `FAMILY_PANEL_KEYS` also keeps it out of the global provider forms.+- Adds `my_bank` to `PANEL_SYNCABLE_TYPES` and `family_panel_items`, which give its+ connection row a sync status and a working Sync button.-**File:** `app/views/settings/providers/show.html.erb` (updated)-- Adds My Bank section with turbo frame+**File:** `app/helpers/settings_helper.rb` (updated)+- Adds a `"my_bank"` case to `provider_summary`, so a connected My Bank is listed under+ Your connections. Keys it doesn't know stay under Available.---@@ -816,11 +778,9 @@ end### Panel Not Showing-1. Check that the provider is excluded in `settings/providers_controller.rb`:+1. Check that `FAMILY_PANELS` in `settings/providers_controller.rb` lists the provider:```ruby- @provider_configurations = Provider::ConfigurationRegistry.all.reject do |config|- config.provider_key.to_s.casecmp("my_bank").zero?- end+ { key: "my_bank", title: "My Bank", turbo_id: "my_bank", partial: "my_bank_panel" }```2. Check that the instance variable is set:@@ -828,15 +788,6 @@ end@my_bank_items = Current.family.my_bank_items.ordered.select(:id)```-3. Check that the section exists in `settings/providers/show.html.erb`:- ```erb- <%= settings_section title: "My Bank" do %>- <turbo-frame id="my-bank-providers-panel">- <%= render "settings/providers/my_bank_panel" %>- </turbo-frame>- <% end %>- ```-### Form Not Submitting1. Check routes are properly added:@@ -844,9 +795,9 @@ endrails routes | grep my_bank```-2. Check turbo frame ID matches:- - View: `<turbo-frame id="my-bank-providers-panel">`- - Controller: Uses `"my-bank-providers-panel"` in turbo_stream.replace+2. Check the panel root ID matches:+ - View: `<div id="my_bank-providers-panel">`+ - `FAMILY_PANELS`: `turbo_id: "my_bank"`, which `render_provider_panel` replaces as `my_bank-providers-panel`### Encryption Not Workingdiff --git a/lib/generators/provider/family/family_generator.rb b/lib/generators/provider/family/family_generator.rbindex 2162b2f531..ce197352c5 100644--- a/lib/generators/provider/family/family_generator.rb+++ b/lib/generators/provider/family/family_generator.rb@@ -339,61 +339,6 @@ class Provider::FamilyGenerator < Rails::Generators::NamedBasecontroller_path = "app/controllers/settings/providers_controller.rb"return unless File.exist?(controller_path)- content = File.read(controller_path)- new_condition = "config.provider_key.to_s.casecmp(\"#{file_name}\").zero?"-- # Check if provider is already excluded- if content.include?(new_condition)- say "Settings controller already excludes #{file_name}", :skip- return- end-- # Add to the rejection list in prepare_show_context- # Look for the end of the reject block and insert before it- if content.include?("reject do |config|")- # Find the reject block's end and insert our condition before it- # The block ends with "end" on its own line after the conditions- lines = content.lines- reject_block_start = nil- reject_block_end = nil-- lines.each_with_index do |line, index|- if line.include?("Provider::ConfigurationRegistry.all.reject do |config|")- reject_block_start = index- elsif reject_block_start && line.strip == "end" && reject_block_end.nil?- reject_block_end = index- break- end- end-- if reject_block_start && reject_block_end- # Find the last condition line (the one before 'end')- last_condition_index = reject_block_end - 1-- # Get indentation from the last condition line- last_condition_line = lines[last_condition_index]- indentation = last_condition_line[/^\s*/]-- # Append our condition with || to the last condition line- # Remove trailing whitespace/newline, add || and new condition- lines[last_condition_index] = last_condition_line.rstrip + " || \\\n#{indentation}#{new_condition}\n"-- write_file(controller_path, lines.join)- say "Added #{file_name} to provider exclusion list", :green- else- say "Could not find reject block boundaries in settings controller", :yellow- end- elsif content.include?("@provider_configurations = Provider::ConfigurationRegistry.all")- # No reject block exists yet, create one- gsub_file controller_path,- "@provider_configurations = Provider::ConfigurationRegistry.all\n",- "@provider_configurations = Provider::ConfigurationRegistry.all.reject do |config|\n #{new_condition}\n end\n"- say "Created provider exclusion block with #{file_name}", :green- else- say "Could not find provider_configurations assignment in settings controller", :yellow- end-- # Re-read content after potential modificationscontent = File.read(controller_path)# Add instance variable for items@@ -422,31 +367,26 @@ class Provider::FamilyGenerator < Rails::Generators::NamedBaseendend- def update_providers_view+ # Bank sync renders a provider's connection row and drawer from FAMILY_PANELS, and+ # FAMILY_PANEL_KEYS keeps it out of the global provider forms. A connected provider+ # moves under Your connections through its provider_summary case, and the row's sync+ # status and Sync button read PANEL_SYNCABLE_TYPES and family_panel_items. The row+ # renders the panel partial, so --skip-view skips all four.+ def add_bank_sync_entriesreturn if options[:skip_view]- view_path = "app/views/settings/providers/show.html.erb"- return unless File.exist?(view_path)-- content = File.read(view_path)-- # Check if section already exists- if content.include?("\"#{file_name}-providers-panel\"")- say "Providers view already has #{class_name} section", :skip- else- # Add section before the last closing div (at end of file)- section_content = <<~ERB-- <%= settings_section title: "#{class_name}", collapsible: true, open: false do %>- <turbo-frame id="#{file_name}-providers-panel">- <%= render "settings/providers/#{file_name}_panel" %>- </turbo-frame>- <% end %>- ERB-- # Insert before the final </div> at the end of file- insert_into_file view_path, section_content, before: /^<\/div>\s*\z/- say "Added #{class_name} section to providers view", :green+ controller_path = "app/controllers/settings/providers_controller.rb"+ add_bank_sync_entry(controller_path, "FAMILY_PANELS", "key: \"#{file_name}\"") do |content|+ self.class.append_family_panel_entry(content, key: file_name, title: class_name.titleize)+ end+ add_bank_sync_entry(controller_path, "PANEL_SYNCABLE_TYPES", "=> \"#{class_name}Item\"") do |content|+ self.class.append_panel_syncable_type(content, key: file_name, class_name: class_name)+ end+ add_bank_sync_entry(controller_path, "family_panel_items", "=> @#{file_name}_items") do |content|+ self.class.append_family_panel_item(content, key: file_name)+ end+ add_bank_sync_entry("app/helpers/settings_helper.rb", "provider_summary", "when \"#{file_name}\"") do |content|+ self.class.append_provider_summary_case(content, key: file_name)endend@@ -586,7 +526,7 @@ class Provider::FamilyGenerator < Rails::Generators::NamedBasesay " - test/models/#{file_name}_account/processor_test.rb"say " 🛣️ Routes: Updated config/routes.rb"say " 🌐 Locale: config/locales/views/#{file_name}_items/en.yml"- say " ⚙️ Settings: Updated controllers, views, and Family model"+ say " ⚙️ Settings: Updated controllers, settings helper and Family model"if parsed_fields.any?say "\nCredential fields:", :cyan@@ -686,8 +626,80 @@ class Provider::FamilyGenerator < Rails::Generators::NamedBasecontent.sub(/(enum :source, \{)([^}]*)(\})/m) { prefix + new_body + suffix }end+ # Appends a panel to Settings::ProvidersController::FAMILY_PANELS.+ def self.append_family_panel_entry(content, key:, title:)+ append_last_entry(content, /(FAMILY_PANELS = \[\n)(.*?)(\n[ \t]*\]\.freeze)/m,+ %({ key: "#{key}", title: "#{title}", turbo_id: "#{key}", partial: "#{key}_panel" }))+ end++ # Maps the panel key to its item model in PANEL_SYNCABLE_TYPES, which the row's sync+ # status and Settings::ProvidersController#sync read.+ def self.append_panel_syncable_type(content, key:, class_name:)+ append_hash_entry(content, /(PANEL_SYNCABLE_TYPES = \{\n)(.*?)(\n[ \t]*\}\.freeze)/m, key, %("#{class_name}Item"))+ end++ # Hands the loaded items to the row's sync status through family_panel_items.+ def self.append_family_panel_item(content, key:)+ append_hash_entry(content, /(def family_panel_items\n[ \t]*\{\n)(.*?)(\n[ \t]*\}\n)/m, key, "@#{key}_items")+ end++ # Adds a `when "<key>"` branch to SettingsHelper#provider_summary, just before the+ # `else` that leaves unknown keys under Available.+ def self.append_provider_summary_case(content, key:)+ pattern = /(def provider_summary\b.*?\n)([ \t]*)(else\n[ \t]*\{ status: :off \}\n)/m+ match = content.match(pattern)+ return nil unless match++ indent = match[2]+ branch = <<~RUBY.gsub(/^/, indent)+ when "#{key}"+ return { status: :off } unless @#{key}_items&.any?+ sync_based_summary(key)+ RUBY++ content.sub(pattern) { match[1] + branch + indent + match[3] }+ end++ # Appends `"key" => value` to a multi-line hash, lining its arrow up with the last entry's.+ def self.append_hash_entry(content, pattern, key, value)+ last = content[pattern, 2]&.rstrip&.lines&.last+ return nil unless last&.include?("=>")++ width = last.index("=>") - last[/\A[ \t]*/].length+ append_last_entry(content, pattern, %("#{key}").ljust(width - 1) + " => #{value}")+ end++ # Appends `entry` to the multi-line literal whose (opening)(body)(closing) `pattern`+ # captures, indented like the last entry, which has no trailing comma and gets one.+ def self.append_last_entry(content, pattern, entry)+ match = content.match(pattern)+ return nil unless match++ body = match[2].rstrip+ indent = body.lines.last[/\A[ \t]*/]+ separator = body.end_with?(",") ? "" : ","++ content.sub(pattern) { match[1] + "#{body}#{separator}\n#{indent}#{entry}" + match[3] }+ end+private+ # Writes the block's result to `path` unless `marker` shows the entry is already there.+ def add_bank_sync_entry(path, name, marker)+ return unless File.exist?(path)++ content = File.read(path)++ if content.include?(marker)+ say "#{name} already lists #{file_name}", :skip+ elsif (updated = yield(content))+ write_file(path, updated)+ say "Added #{file_name} to #{name}", :green+ else+ say "Could not find #{name} in #{path}", :yellow+ end+ end+def update_source_enum(model_path)return unless File.exist?(model_path)diff --git a/lib/generators/provider/family/templates/controller.rb.tt b/lib/generators/provider/family/templates/controller.rb.ttindex 99677a814b..653806539e 100644--- a/lib/generators/provider/family/templates/controller.rb.tt+++ b/lib/generators/provider/family/templates/controller.rb.tt@@ -24,63 +24,17 @@ class <%= class_name %>ItemsController < ApplicationController@<%= file_name %>_item.name ||= "<%= class_name %> Connection"if @<%= file_name %>_item.save- if turbo_frame_request?- flash.now[:notice] = t(".success", default: "Successfully configured <%= class_name %>.")- @<%= table_name %> = Current.family.<%= table_name %>.ordered- render turbo_stream: [- turbo_stream.replace(- "<%= file_name %>-providers-panel",- partial: "settings/providers/<%= file_name %>_panel",- locals: { <%= file_name %>_items: @<%= table_name %> }- ),- *flash_notification_stream_items- ]- else- redirect_to settings_providers_path, notice: t(".success"), status: :see_other- end+ redirect_to settings_providers_path, notice: t(".success"), status: :see_otherelse- @error_message = @<%= file_name %>_item.errors.full_messages.join(", ")-- if turbo_frame_request?- render turbo_stream: turbo_stream.replace(- "<%= file_name %>-providers-panel",- partial: "settings/providers/<%= file_name %>_panel",- locals: { error_message: @error_message }- ), status: :unprocessable_entity- else- redirect_to settings_providers_path, alert: @error_message, status: :unprocessable_entity- end+ render_provider_panel("<%= file_name %>", alert: @<%= file_name %>_item.errors.full_messages.join(", "))endenddef updateif @<%= file_name %>_item.update(<%= file_name %>_item_params)- if turbo_frame_request?- flash.now[:notice] = t(".success", default: "Successfully updated <%= class_name %> configuration.")- @<%= table_name %> = Current.family.<%= table_name %>.ordered- render turbo_stream: [- turbo_stream.replace(- "<%= file_name %>-providers-panel",- partial: "settings/providers/<%= file_name %>_panel",- locals: { <%= file_name %>_items: @<%= table_name %> }- ),- *flash_notification_stream_items- ]- else- redirect_to settings_providers_path, notice: t(".success"), status: :see_other- end+ render_provider_panel("<%= file_name %>", notice: t(".success"))else- @error_message = @<%= file_name %>_item.errors.full_messages.join(", ")-- if turbo_frame_request?- render turbo_stream: turbo_stream.replace(- "<%= file_name %>-providers-panel",- partial: "settings/providers/<%= file_name %>_panel",- locals: { error_message: @error_message }- ), status: :unprocessable_entity- else- redirect_to settings_providers_path, alert: @error_message, status: :unprocessable_entity- end+ render_provider_panel("<%= file_name %>", alert: @<%= file_name %>_item.errors.full_messages.join(", "))endenddiff --git a/lib/generators/provider/family/templates/panel.html.erb.tt b/lib/generators/provider/family/templates/panel.html.erb.ttindex 49611723e1..a689b3aa37 100644--- a/lib/generators/provider/family/templates/panel.html.erb.tt+++ b/lib/generators/provider/family/templates/panel.html.erb.tt@@ -1,4 +1,4 @@-<div class="space-y-4">+<div id="<%= file_name %>-providers-panel" class="space-y-4"><div class="prose prose-sm text-secondary"><p class="text-primary font-medium"><%= "<" + "%= t(\"#{file_name}_items.panel.setup_instructions\") %" + ">" %></p><ol>diff --git a/test/controllers/akahu_items_controller_test.rb b/test/controllers/akahu_items_controller_test.rbindex 7a3cec9fff..b409abe7ec 100644--- a/test/controllers/akahu_items_controller_test.rb+++ b/test/controllers/akahu_items_controller_test.rb@@ -21,6 +21,23 @@ class AkahuItemsControllerTest < ActionDispatch::IntegrationTest@account = accounts(:depository)end+ # Redirecting back to Bank sync would collapse the open connection row.+ test "sync from the panel re-renders the panel in place" do+ post sync_akahu_item_url(@akahu_item, source: "panel"), as: :turbo_stream++ assert_turbo_stream action: "replace", target: "akahu-providers-panel"+ assert_includes response.body, I18n.t("settings.providers.sync_provider_in_progress")+ assert @akahu_item.reload.syncing?+ end++ # The Accounts page's Sync button posts here too, without the panel's source.+ test "sync from the Accounts page goes back to it" do+ post sync_akahu_item_url(@akahu_item),+ headers: { "Accept" => "text/vnd.turbo-stream.html, text/html, application/xhtml+xml", "Referer" => accounts_url }++ assert_redirected_to accounts_url+ end+test "setup_accounts preselects mapped account type for each account" doAkahuItemsController.any_instance.stubs(:fetch_akahu_accounts_from_api).returns(nil)@@ -259,6 +276,47 @@ class AkahuItemsControllerTest < ActionDispatch::IntegrationTestrefute_includes response.body, "Akahu Checking"end+ # The row and drawer panels post from the page, not a frame. Turbo only+ # follows a 3xx, so a 422 redirect left the form with no feedback.+ test "invalid create outside a frame redirects to the providers page with a 303" do+ assert_no_difference "AkahuItem.count" do+ post akahu_items_url, params: { akahu_item: { app_token: "", user_token: "" } }+ end++ assert_response :see_other+ assert_redirected_to settings_providers_path+ assert_match "can't be blank", flash[:alert]+ end++ # Redirecting back to Bank sync collapses the open connection row.+ test "update from the page re-renders the panel in place" do+ patch akahu_item_url(@akahu_item),+ params: { akahu_item: { name: "Renamed Akahu" } },+ as: :turbo_stream++ assert_turbo_stream action: "replace", target: "akahu-providers-panel"+ assert_includes response.body, %(id="akahu-providers-panel")+ assert_equal "Renamed Akahu", @akahu_item.reload.name+ end++ test "invalid create from the page shows the error in the panel" do+ post akahu_items_url,+ params: { akahu_item: { app_token: "", user_token: "" } },+ as: :turbo_stream++ assert_turbo_stream status: :unprocessable_entity, action: "replace", target: "akahu-providers-panel"+ assert_includes response.body, ERB::Util.html_escape("can't be blank")+ end++ # The new connection belongs in Your connections, so the page reloads.+ test "create from the page still reloads Bank sync" do+ post akahu_items_url,+ params: { akahu_item: { app_token: "new-app-credential", user_token: "new-user-credential" } },+ as: :turbo_stream++ assert_redirected_to settings_providers_path+ end+test "complete account setup hides raw creation errors from users" doraw_message = "raw provider failure with akahu-user-credential"AkahuItemsController.any_instancediff --git a/test/controllers/binance_items_controller_test.rb b/test/controllers/binance_items_controller_test.rbindex d8bdc8e891..a063b3a9f4 100644--- a/test/controllers/binance_items_controller_test.rb+++ b/test/controllers/binance_items_controller_test.rb@@ -24,11 +24,30 @@ class BinanceItemsControllerTest < ActionDispatch::IntegrationTestassert @binance_item.scheduled_for_deletion?end+ test "invalid create from the page shows the error in the panel" do+ post binance_items_url,+ params: { binance_item: { api_key: "", api_secret: "" } },+ as: :turbo_stream++ assert_turbo_stream status: :unprocessable_entity, action: "replace", target: "binance-providers-panel"+ assert_includes response.body, %(id="binance-providers-panel")+ assert_includes response.body, ERB::Util.html_escape("can't be blank")+ end+test "should sync binance item" dopost sync_binance_item_url(@binance_item)assert_response :redirectend+ # Redirecting back to Bank sync would collapse the open connection row.+ test "sync from the panel re-renders the panel in place" do+ post sync_binance_item_url(@binance_item, source: "panel"), as: :turbo_stream++ assert_turbo_stream action: "replace", target: "binance-providers-panel"+ assert_includes response.body, I18n.t("settings.providers.sync_provider_in_progress")+ assert @binance_item.reload.syncing?+ end+test "should show setup_accounts page" doget setup_accounts_binance_item_url(@binance_item)assert_response :successdiff --git a/test/controllers/brex_items_controller_test.rb b/test/controllers/brex_items_controller_test.rbindex b443f2023c..1d626e6f1d 100644--- a/test/controllers/brex_items_controller_test.rb+++ b/test/controllers/brex_items_controller_test.rb@@ -73,6 +73,24 @@ class BrexItemsControllerTest < ActionDispatch::IntegrationTestassert_equal "https://api-staging.brex.com", @second_item.base_urlend+ test "update from the page re-renders the panel in place instead of leaving for accounts" do+ patch brex_item_url(@second_item),+ params: { brex_item: { name: "Renamed Business Brex" } },+ as: :turbo_stream++ assert_turbo_stream action: "replace", target: "brex-providers-panel"+ assert_includes response.body, %(id="brex-providers-panel")+ assert_equal "Renamed Business Brex", @second_item.reload.name+ end++ test "create from the page still moves on to accounts" do+ post brex_items_url,+ params: { brex_item: { name: "Joint Brex", token: "joint_brex_token" } },+ as: :turbo_stream++ assert_redirected_to accounts_path+ end+test "update rejects arbitrary brex base url" dopatch brex_item_url(@second_item), params: {brex_item: {@@ -408,6 +426,15 @@ class BrexItemsControllerTest < ActionDispatch::IntegrationTestassert_response :redirectend+ # Redirecting back to Bank sync would collapse the open connection row.+ test "sync from the panel re-renders the panel in place" do+ post sync_brex_item_url(@second_item, source: "panel"), as: :turbo_stream++ assert_turbo_stream action: "replace", target: "brex-providers-panel"+ assert_includes response.body, I18n.t("settings.providers.sync_provider_in_progress")+ assert @second_item.reload.syncing?+ end+test "complete account setup ignores unsupported account type and subtype params" dovalid_brex_account = @second_item.brex_accounts.create!(account_id: "setup_valid",diff --git a/test/controllers/coinbase_items_controller_test.rb b/test/controllers/coinbase_items_controller_test.rbindex 9dc0878f41..721c70ed66 100644--- a/test/controllers/coinbase_items_controller_test.rb+++ b/test/controllers/coinbase_items_controller_test.rb@@ -24,11 +24,47 @@ class CoinbaseItemsControllerTest < ActionDispatch::IntegrationTestassert @coinbase_item.scheduled_for_deletion?end+ test "invalid create outside a frame redirects to the providers page with a 303" do+ assert_no_difference "CoinbaseItem.count" do+ post coinbase_items_url, params: { coinbase_item: { api_key: "", api_secret: "" } }+ end++ assert_response :see_other+ assert_redirected_to settings_providers_path+ assert_match "can't be blank", flash[:alert]+ end++ test "invalid create from the page shows the error in the panel" do+ post coinbase_items_url,+ params: { coinbase_item: { api_key: "", api_secret: "" } },+ as: :turbo_stream++ assert_turbo_stream status: :unprocessable_entity, action: "replace", target: "coinbase-providers-panel"+ assert_includes response.body, ERB::Util.html_escape("can't be blank")+ end++ test "invalid update outside a frame redirects to the providers page with a 303" do+ patch coinbase_item_url(@coinbase_item), params: { coinbase_item: { api_key: "" } }++ assert_response :see_other+ assert_redirected_to settings_providers_path+ assert_match "can't be blank", flash[:alert]+ end+test "should sync coinbase item" dopost sync_coinbase_item_url(@coinbase_item)assert_response :redirectend+ # Redirecting back to Bank sync would collapse the open connection row.+ test "sync from the panel re-renders the panel in place" do+ post sync_coinbase_item_url(@coinbase_item, source: "panel"), as: :turbo_stream++ assert_turbo_stream action: "replace", target: "coinbase-providers-panel"+ assert_includes response.body, I18n.t("settings.providers.sync_provider_in_progress")+ assert @coinbase_item.reload.syncing?+ end+test "should show setup_accounts page" doget setup_accounts_coinbase_item_url(@coinbase_item)assert_response :successdiff --git a/test/controllers/coinspot_items_controller_test.rb b/test/controllers/coinspot_items_controller_test.rbindex fe516d0bf4..606d11ce0a 100644--- a/test/controllers/coinspot_items_controller_test.rb+++ b/test/controllers/coinspot_items_controller_test.rb@@ -96,13 +96,33 @@ class CoinspotItemsControllerTest < ActionDispatch::IntegrationTestapi_key: " ",api_secret: "\n"}- }, as: :turbo_stream, headers: { "Turbo-Frame" => "coinspot-providers-panel" }+ }, as: :turbo_streamassert_response :unprocessable_entityassert_includes @response.body, "coinspot-providers-panel"assert_includes @response.body, "Api key can't be blank"end+ # Redirecting back to Bank sync collapses the open connection row. The panel+ # root carries the id, so it is replaced rather than nested inside itself.+ test "update from the page re-renders the panel in place" do+ patch coinspot_item_url(@second_item),+ params: { coinspot_item: { name: "Renamed Business CoinSpot" } },+ as: :turbo_stream++ assert_turbo_stream action: "replace", target: "coinspot-providers-panel"+ assert_includes response.body, %(id="coinspot-providers-panel")+ assert_equal "Renamed Business CoinSpot", @second_item.reload.name+ end++ test "create from the page still reloads Bank sync" do+ post coinspot_items_url,+ params: { coinspot_item: { name: "Joint CoinSpot", api_key: "joint_coinspot_key", api_secret: "joint_coinspot_secret" } },+ as: :turbo_stream++ assert_redirected_to settings_providers_path+ end+test "select accounts requires an explicit connection when multiple coinspot items exist" doget select_accounts_coinspot_items_url, params: { accountable_type: "Crypto" }@@ -139,6 +159,15 @@ class CoinspotItemsControllerTest < ActionDispatch::IntegrationTestassert_response :redirectend+ # Redirecting back to Bank sync would collapse the open connection row.+ test "sync from the panel re-renders the panel in place" do+ post sync_coinspot_item_url(@second_item, source: "panel"), as: :turbo_stream++ assert_turbo_stream action: "replace", target: "coinspot-providers-panel"+ assert_includes response.body, I18n.t("settings.providers.sync_provider_in_progress")+ assert @second_item.reload.syncing?+ end+test "setup accounts creates crypto exchange account for selected item only" dofirst_account = coinspot_accounts(:one)second_account = @second_item.coinspot_accounts.create!(diff --git a/test/controllers/coinstats_items_controller_test.rb b/test/controllers/coinstats_items_controller_test.rbindex 916a963347..30c3545b80 100644--- a/test/controllers/coinstats_items_controller_test.rb+++ b/test/controllers/coinstats_items_controller_test.rb@@ -55,6 +55,46 @@ class CoinstatsItemsControllerTest < ActionDispatch::IntegrationTestendend+ test "invalid create outside a frame redirects to the providers page with a 303" do+ assert_no_difference "CoinstatsItem.count" do+ post coinstats_items_url, params: { coinstats_item: { name: "New CoinStats Connection", api_key: "" } }+ end++ assert_response :see_other+ assert_redirected_to settings_providers_path+ assert_match "can't be blank", flash[:alert]+ end++ # Redirecting back to Bank sync collapses the open connection row.+ test "update from the page re-renders the panel in place" do+ patch coinstats_item_url(@coinstats_item),+ params: { coinstats_item: { name: "Renamed CoinStats" } },+ as: :turbo_stream++ assert_turbo_stream action: "replace", target: "coinstats-providers-panel"+ assert_includes response.body, %(id="coinstats-providers-panel")+ assert_equal "Renamed CoinStats", @coinstats_item.reload.name+ end++ test "invalid create from the page shows the error in the panel" do+ post coinstats_items_url,+ params: { coinstats_item: { name: "New CoinStats Connection", api_key: "" } },+ as: :turbo_stream++ assert_turbo_stream status: :unprocessable_entity, action: "replace", target: "coinstats-providers-panel"+ assert_includes response.body, ERB::Util.html_escape("can't be blank")+ end++ test "create from the page still reloads Bank sync" do+ Provider::Coinstats.any_instance.expects(:get_blockchains).returns(success_response([])).once++ post coinstats_items_url,+ params: { coinstats_item: { name: "New CoinStats Connection", api_key: "valid_api_key" } },+ as: :turbo_stream++ assert_redirected_to settings_providers_path+ end+test "should destroy coinstats item" do# Schedules for deletion, doesn't actually delete immediatelyassert_no_difference("CoinstatsItem.count") dodiff --git a/test/controllers/enable_banking_items_controller_test.rb b/test/controllers/enable_banking_items_controller_test.rbindex 424a5aa645..244c9b100b 100644--- a/test/controllers/enable_banking_items_controller_test.rb+++ b/test/controllers/enable_banking_items_controller_test.rb@@ -40,6 +40,62 @@ class EnableBankingItemsControllerTest < ActionDispatch::IntegrationTest"Expected the searchable data attribute to still include the bank name (existing name-search behavior)"end+ # Redirecting back to Bank sync would collapse the open connection row.+ test "sync from the panel re-renders the panel in place" do+ post sync_enable_banking_item_url(@item, source: "panel"), as: :turbo_stream++ assert_turbo_stream action: "replace", target: "enable_banking-providers-panel"+ assert_includes response.body, I18n.t("settings.providers.sync_provider_in_progress")+ assert @item.reload.syncing?+ end++ # The Accounts page's Sync button posts here too, without the panel's source.+ test "sync from the Accounts page goes back to it" do+ post sync_enable_banking_item_url(@item),+ headers: { "Accept" => "text/vnd.turbo-stream.html, text/html, application/xhtml+xml", "Referer" => accounts_url }++ assert_redirected_to accounts_url+ end++ test "invalid create outside a frame redirects to the providers page with a 303" do+ assert_no_difference "EnableBankingItem.count" do+ post enable_banking_items_url, params: { enable_banking_item: { country_code: "", application_id: "" } }+ end++ assert_response :see_other+ assert_redirected_to settings_providers_path+ assert_match "can't be blank", flash[:alert]+ end++ test "invalid update outside a frame redirects to the providers page with a 303" do+ patch enable_banking_item_url(@item), params: { enable_banking_item: { country_code: "" } }++ assert_response :see_other+ assert_redirected_to settings_providers_path+ assert_match "can't be blank", flash[:alert]+ assert_equal "DE", @item.reload.country_code+ end++ # Redirecting back to Bank sync collapses the open connection row.+ test "update from the page re-renders the panel in place" do+ patch enable_banking_item_url(@item),+ params: { enable_banking_item: { name: "Renamed Connection" } },+ as: :turbo_stream++ assert_turbo_stream action: "replace", target: "enable_banking-providers-panel"+ assert_includes response.body, %(id="enable_banking-providers-panel")+ assert_equal "Renamed Connection", @item.reload.name+ end++ test "invalid create from the page shows the error in the panel" do+ post enable_banking_items_url,+ params: { enable_banking_item: { country_code: "", application_id: "" } },+ as: :turbo_stream++ assert_turbo_stream status: :unprocessable_entity, action: "replace", target: "enable_banking-providers-panel"+ assert_includes response.body, ERB::Util.html_escape("can't be blank")+ end+test "authorize no longer blocks decoupled banks and proceeds to the hosted auth page" doProvider::EnableBanking.any_instance.stubs(:get_aspsps).returns(aspsps: [diff --git a/test/controllers/fio_items_controller_test.rb b/test/controllers/fio_items_controller_test.rbindex adce5d0535..8cb67d535a 100644--- a/test/controllers/fio_items_controller_test.rb+++ b/test/controllers/fio_items_controller_test.rb@@ -40,6 +40,35 @@ class FioItemsControllerTest < ActionDispatch::IntegrationTestassert_equal I18n.t("fio_items.create.token_required"), flash[:alert]end+ test "invalid create from the page shows the error in the panel" do+ post fio_items_url,+ params: { fio_item: { name: "No token", token: " " } },+ as: :turbo_stream++ assert_turbo_stream status: :unprocessable_entity, action: "replace", target: "fio-providers-panel"+ assert_includes response.body, ERB::Util.html_escape(I18n.t("fio_items.create.token_required"))+ end++ # The new connection belongs in Your connections, so the page reloads.+ test "create from the page still reloads Bank sync" do+ post fio_items_url,+ params: { fio_item: { name: "Savings", token: "second-token" } },+ as: :turbo_stream++ assert_redirected_to settings_providers_path+ end++ # Redirecting back to Bank sync collapses the open connection row.+ test "update from the page re-renders the panel in place" do+ patch fio_item_url(@fio_item),+ params: { fio_item: { name: "Renamed Fio", token: "" } },+ as: :turbo_stream++ assert_turbo_stream action: "replace", target: "fio-providers-panel"+ assert_includes response.body, %(id="fio-providers-panel")+ assert_equal "Renamed Fio", @fio_item.reload.name+ end+# The form sets the status, so only a sync can establish whether Fio accepts the new# token — without one the connection would claim to be healthy on the user's word.test "update rotates the token, clears requires_update and revalidates it" do@@ -97,6 +126,15 @@ class FioItemsControllerTest < ActionDispatch::IntegrationTestassert_redirected_to accounts_pathend+ # Redirecting back to Bank sync would collapse the open connection row.+ test "sync from the panel re-renders the panel in place" do+ post sync_fio_item_url(@fio_item, source: "panel"), as: :turbo_stream++ assert_turbo_stream action: "replace", target: "fio-providers-panel"+ assert_includes response.body, I18n.t("settings.providers.sync_provider_in_progress")+ assert @fio_item.reload.syncing?+ end+test "destroy unlinks the account and schedules the connection for deletion" do@fio_account.ensure_account_provider!(accounts(:depository))DestroyJob.expects(:perform_later).with(@fio_item).oncediff --git a/test/controllers/ibkr_items_controller_test.rb b/test/controllers/ibkr_items_controller_test.rbindex fbb0bccb09..ab5c2b797e 100644--- a/test/controllers/ibkr_items_controller_test.rb+++ b/test/controllers/ibkr_items_controller_test.rb@@ -6,6 +6,23 @@ class IbkrItemsControllerTest < ActionDispatch::IntegrationTest@ibkr_item = ibkr_items(:configured_item)end+ # Redirecting back to Bank sync would collapse the open connection row.+ test "sync from the panel re-renders the panel in place" do+ post sync_ibkr_item_url(@ibkr_item, source: "panel"), as: :turbo_stream++ assert_turbo_stream action: "replace", target: "ibkr-providers-panel"+ assert_includes response.body, I18n.t("settings.providers.sync_provider_in_progress")+ assert @ibkr_item.reload.syncing?+ end++ # The Accounts page's Sync button posts here too, without the panel's source.+ test "sync from the Accounts page goes back to it" do+ post sync_ibkr_item_url(@ibkr_item),+ headers: { "Accept" => "text/vnd.turbo-stream.html, text/html, application/xhtml+xml", "Referer" => accounts_url }++ assert_redirected_to accounts_url+ end+test "select_existing_account renders available ibkr accounts" doget select_existing_account_ibkr_items_url, params: { account_id: accounts(:investment).id }@@ -37,6 +54,24 @@ class IbkrItemsControllerTest < ActionDispatch::IntegrationTestassert_redirected_to accounts_pathend+ test "invalid create from the page shows the error in the panel" do+ post ibkr_items_url,+ params: { ibkr_item: { query_id: "", token: "" } },+ as: :turbo_stream++ assert_turbo_stream status: :unprocessable_entity, action: "replace", target: "ibkr-providers-panel"+ assert_includes response.body, ERB::Util.html_escape("can't be blank")+ end++ test "update from the page re-renders the panel in place instead of leaving for accounts" do+ patch ibkr_item_url(@ibkr_item),+ params: { ibkr_item: { query_id: "", token: "" } },+ as: :turbo_stream++ assert_turbo_stream action: "replace", target: "ibkr-providers-panel"+ assert_includes response.body, %(id="ibkr-providers-panel")+ end+test "complete_account_setup creates investment account and provider link" doassert_difference "Account.count", 1 doassert_difference "AccountProvider.count", 1 dodiff --git a/test/controllers/indexa_capital_items_controller_test.rb b/test/controllers/indexa_capital_items_controller_test.rbindex f382bb275c..fee57a0edd 100644--- a/test/controllers/indexa_capital_items_controller_test.rb+++ b/test/controllers/indexa_capital_items_controller_test.rb@@ -31,6 +31,44 @@ class IndexaCapitalItemsControllerTest < ActionDispatch::IntegrationTestassert_equal "Updated Name", @item.nameend+ test "invalid create outside a frame redirects to the providers page with a 303" do+ assert_no_difference "IndexaCapitalItem.count" do+ post indexa_capital_items_url, params: { indexa_capital_item: { name: "New Connection" } }+ end++ assert_response :see_other+ assert_redirected_to settings_providers_path+ assert_equal I18n.t("activerecord.errors.models.indexa_capital_item.credentials_required"), flash[:alert]+ end++ test "invalid update outside a frame redirects to the providers page with a 303" do+ patch indexa_capital_item_url(@item), params: { indexa_capital_item: { name: "" } }++ assert_response :see_other+ assert_redirected_to settings_providers_path+ assert_match "can't be blank", flash[:alert]+ end++ # Redirecting back to Bank sync collapses the open connection row.+ test "update from the page re-renders the panel in place" do+ patch indexa_capital_item_url(@item),+ params: { indexa_capital_item: { name: "Updated Name" } },+ as: :turbo_stream++ assert_turbo_stream action: "replace", target: "indexa_capital-providers-panel"+ assert_includes response.body, %(id="indexa_capital-providers-panel")+ assert_equal "Updated Name", @item.reload.name+ end++ test "invalid create from the page shows the error in the panel" do+ post indexa_capital_items_url,+ params: { indexa_capital_item: { name: "New Connection" } },+ as: :turbo_stream++ assert_turbo_stream status: :unprocessable_entity, action: "replace", target: "indexa_capital-providers-panel"+ assert_includes response.body, ERB::Util.html_escape(I18n.t("activerecord.errors.models.indexa_capital_item.credentials_required"))+ end+test "should destroy indexa_capital_item" doassert_difference("IndexaCapitalItem.count", 0) do # doesn't delete immediatelydelete indexa_capital_item_url(@item)diff --git a/test/controllers/kraken_items_controller_test.rb b/test/controllers/kraken_items_controller_test.rbindex e287fcecb9..b740e9d338 100644--- a/test/controllers/kraken_items_controller_test.rb+++ b/test/controllers/kraken_items_controller_test.rb@@ -89,6 +89,36 @@ class KrakenItemsControllerTest < ActionDispatch::IntegrationTestassert_match(/API key can't be blank/i, flash[:alert])end+ test "invalid create from the page shows the error in the panel" do+ post kraken_items_url,+ params: { kraken_item: { name: "Blank Kraken", api_key: " ", api_secret: "\n" } },+ as: :turbo_stream++ assert_turbo_stream status: :unprocessable_entity, action: "replace", target: "kraken-providers-panel"+ assert_includes response.body, ERB::Util.html_escape("Api key can't be blank")+ end++ # The new connection belongs in Your connections, so the page reloads.+ test "create from the page still reloads Bank sync" do+ post kraken_items_url,+ params: { kraken_item: { name: "Joint Kraken", api_key: "joint_kraken_key", api_secret: "joint_kraken_secret" } },+ as: :turbo_stream++ assert_redirected_to settings_providers_path+ end++ # Redirecting back to Bank sync collapses the open connection row. The panel+ # root carries the id, so it is replaced rather than nested inside itself.+ test "update from the page re-renders the panel in place" do+ patch kraken_item_url(@second_item),+ params: { kraken_item: { name: "Renamed Business Kraken" } },+ as: :turbo_stream++ assert_turbo_stream action: "replace", target: "kraken-providers-panel"+ assert_includes response.body, %(id="kraken-providers-panel")+ assert_equal "Renamed Business Kraken", @second_item.reload.name+ end+test "select accounts requires an explicit connection when multiple kraken items exist" doget select_accounts_kraken_items_url, params: { accountable_type: "Crypto" }@@ -125,6 +155,15 @@ class KrakenItemsControllerTest < ActionDispatch::IntegrationTestassert_response :redirectend+ # Redirecting back to Bank sync would collapse the open connection row.+ test "sync from the panel re-renders the panel in place" do+ post sync_kraken_item_url(@second_item, source: "panel"), as: :turbo_stream++ assert_turbo_stream action: "replace", target: "kraken-providers-panel"+ assert_includes response.body, I18n.t("settings.providers.sync_provider_in_progress")+ assert @second_item.reload.syncing?+ end+test "setup accounts creates crypto exchange account for selected item only" dofirst_account = kraken_accounts(:one)second_account = @second_item.kraken_accounts.create!(diff --git a/test/controllers/lunchflow_items_controller_test.rb b/test/controllers/lunchflow_items_controller_test.rbindex 5432a893f5..597563cb53 100644--- a/test/controllers/lunchflow_items_controller_test.rb+++ b/test/controllers/lunchflow_items_controller_test.rb@@ -5,6 +5,34 @@ class LunchflowItemsControllerTest < ActionDispatch::IntegrationTestsign_in @user = users(:family_admin)end+ test "update from the page re-renders the panel in place instead of leaving for accounts" do+ patch lunchflow_item_url(lunchflow_items(:one)),+ params: { lunchflow_item: { name: "Renamed Lunch Flow" } },+ as: :turbo_stream++ assert_turbo_stream action: "replace", target: "lunchflow-providers-panel"+ assert_includes response.body, %(id="lunchflow-providers-panel")+ assert_equal "Renamed Lunch Flow", lunchflow_items(:one).reload.name+ end++ test "invalid create from the page shows the error in the panel" do+ post lunchflow_items_url,+ params: { lunchflow_item: { name: "Second Lunch Flow", api_key: "" } },+ as: :turbo_stream++ assert_turbo_stream status: :unprocessable_entity, action: "replace", target: "lunchflow-providers-panel"+ assert_includes response.body, ERB::Util.html_escape("Api key can't be blank")+ end++ test "invalid non-Turbo update redirects back instead of rendering a missing template" do+ patch lunchflow_item_url(lunchflow_items(:one)),+ params: { lunchflow_item: { name: "" } },+ headers: { "HTTP_REFERER" => settings_providers_url }++ assert_redirected_to settings_providers_url+ assert_match "Name can't be blank", flash[:alert]+ end+test "setup accounts renders German subtype options without English fallbacks" doensure_tailwind_build@user.update!(locale: "de")@@ -159,7 +187,7 @@ class LunchflowItemsControllerTest < ActionDispatch::IntegrationTest}end- assert_redirected_to accounts_path+ assert_redirected_to settings_providers_pathassert_match "Api key can't be blank", flash[:alert]endenddiff --git a/test/controllers/mercury_items_controller_test.rb b/test/controllers/mercury_items_controller_test.rbindex fbd7d3cc96..ce55f0ca86 100644--- a/test/controllers/mercury_items_controller_test.rb+++ b/test/controllers/mercury_items_controller_test.rb@@ -58,6 +58,63 @@ class MercuryItemsControllerTest < ActionDispatch::IntegrationTestassert_equal "https://api-sandbox.mercury.com/api/v1", @second_item.base_urlend+ test "invalid create outside a frame redirects instead of rendering a missing template" do+ assert_no_difference "MercuryItem.count" do+ post mercury_items_url, params: { mercury_item: { name: "Joint Mercury", token: "" } }+ end++ assert_response :see_other+ assert_redirected_to settings_providers_path+ assert_match "Token can't be blank", flash[:alert]+ end++ test "invalid create from the page shows the error in the panel" do+ post mercury_items_url,+ params: { mercury_item: { name: "Joint Mercury", token: "" } },+ as: :turbo_stream++ assert_turbo_stream status: :unprocessable_entity, action: "replace", target: "mercury-providers-panel"+ assert_includes response.body, ERB::Util.html_escape("Token can't be blank")+ end++ test "invalid update outside a frame redirects instead of rendering a missing template" do+ patch mercury_item_url(@second_item), params: { mercury_item: { name: "" } }++ assert_response :see_other+ assert_redirected_to settings_providers_path+ assert_match "Name can't be blank", flash[:alert]+ assert_equal "Business Mercury", @second_item.reload.name+ end++ # Connection rows post from the page, so Turbo asks for a stream without a Turbo-Frame header.+ test "update from the page re-renders the panel in place instead of leaving for accounts" do+ patch mercury_item_url(@second_item),+ params: { mercury_item: { name: "Renamed Business Mercury" } },+ as: :turbo_stream++ assert_turbo_stream action: "replace", target: "mercury-providers-panel"+ assert_includes response.body, %(id="mercury-providers-panel")+ assert_equal "Renamed Business Mercury", @second_item.reload.name+ end++ test "invalid update from the page re-renders the panel with the error" do+ patch mercury_item_url(@second_item),+ params: { mercury_item: { name: "" } },+ as: :turbo_stream++ assert_turbo_stream status: :unprocessable_entity, action: "replace", target: "mercury-providers-panel"+ assert_includes response.body, ERB::Util.html_escape("Name can't be blank")+ end++ # Redirecting back to Bank sync would collapse the open connection row.+ test "sync from the panel re-renders the panel in place" do+ post sync_mercury_item_url(@second_item, source: "panel"), as: :turbo_stream++ assert_turbo_stream action: "replace", target: "mercury-providers-panel"+ assert_includes response.body, I18n.t("settings.providers.sync_provider_in_progress")+ assert @second_item.reload.syncing?+ end+test "blank token update preserves the selected mercury token" dooriginal_token = @second_item.tokendiff --git a/test/controllers/monobank_items_controller_test.rb b/test/controllers/monobank_items_controller_test.rbindex 5538b270fb..a235798258 100644--- a/test/controllers/monobank_items_controller_test.rb+++ b/test/controllers/monobank_items_controller_test.rb@@ -49,6 +49,35 @@ class MonobankItemsControllerTest < ActionDispatch::IntegrationTestassert_equal "monobank-personal-token", @monobank_item.access_tokenend+ # Redirecting back to Bank sync collapses the open connection row.+ test "update from the page re-renders the panel in place" do+ patch monobank_item_url(@monobank_item),+ params: { monobank_item: { name: "Renamed Monobank", access_token: "" } },+ as: :turbo_stream++ assert_turbo_stream action: "replace", target: "monobank-providers-panel"+ assert_includes response.body, %(id="monobank-providers-panel")+ assert_equal "Renamed Monobank", @monobank_item.reload.name+ end++ test "invalid create from the page shows the error in the panel" do+ post monobank_items_url,+ params: { monobank_item: { name: "Second Monobank", access_token: "" } },+ as: :turbo_stream++ assert_turbo_stream status: :unprocessable_entity, action: "replace", target: "monobank-providers-panel"+ assert_includes response.body, ERB::Util.html_escape("Access token can't be blank")+ end++ # The new connection belongs in Your connections, so the page reloads.+ test "create from the page still reloads Bank sync" do+ post monobank_items_url,+ params: { monobank_item: { name: "Second Monobank", access_token: "another-token" } },+ as: :turbo_stream++ assert_redirected_to settings_providers_path+ end+test "setup_accounts renders the pending accounts with a preselected type" doMonobankItemsController.any_instance.stubs(:fetch_monobank_accounts_from_api).returns(nil)@@ -144,6 +173,15 @@ class MonobankItemsControllerTest < ActionDispatch::IntegrationTestassert_redirected_to accounts_pathend+ # Redirecting back to Bank sync would collapse the open connection row.+ test "sync from the panel re-renders the panel in place" do+ post sync_monobank_item_url(@monobank_item, source: "panel"), as: :turbo_stream++ assert_turbo_stream action: "replace", target: "monobank-providers-panel"+ assert_includes response.body, I18n.t("settings.providers.sync_provider_in_progress")+ assert @monobank_item.reload.syncing?+ end+test "destroy schedules the connection for deletion" doDestroyJob.expects(:perform_later).with(@monobank_item).oncediff --git a/test/controllers/onchain_wallet_items_controller_test.rb b/test/controllers/onchain_wallet_items_controller_test.rbindex 587938eda3..5bca4508ca 100644--- a/test/controllers/onchain_wallet_items_controller_test.rb+++ b/test/controllers/onchain_wallet_items_controller_test.rb@@ -399,6 +399,20 @@ class OnchainWalletItemsControllerTest < ActionDispatch::IntegrationTestassert_equal Date.new(2026, 1, 15), item.reload.sync_start_date.to_dateend+ # Redirecting back to Bank sync collapses the open connection row. The panel+ # root carries the id, so it is replaced rather than nested inside itself.+ test "update from the page re-renders the panel in place" do+ item = create_onchain_wallet_item(family: @family)++ patch onchain_wallet_item_url(item),+ params: { onchain_wallet_item: { sync_start_date: "2026-01-15" } },+ as: :turbo_stream++ assert_turbo_stream action: "replace", target: "onchain_wallet-providers-panel"+ assert_includes response.body, %(id="onchain_wallet-providers-panel")+ assert_equal Date.new(2026, 1, 15), item.reload.sync_start_date.to_date+ end+test "linking creates the single connection every wallet hangs off" dostub_wallet_with_tokenstub_wallet_with_token(address: OnchainTestHelper::FAKE_ADDRESS_ALT)diff --git a/test/controllers/questrade_items_controller_test.rb b/test/controllers/questrade_items_controller_test.rbindex 8d8a862a50..fb48d86d16 100644--- a/test/controllers/questrade_items_controller_test.rb+++ b/test/controllers/questrade_items_controller_test.rb@@ -37,6 +37,15 @@ class QuestradeItemsControllerTest < ActionDispatch::IntegrationTestassert_equal I18n.t("questrade_items.default_name"), @family.questrade_items.order(:created_at).last.nameend+ test "invalid create from the page shows the error in the panel" do+ post questrade_items_url,+ params: { questrade_item: { name: "Business Questrade", refresh_token: "" } },+ as: :turbo_stream++ assert_turbo_stream status: :unprocessable_entity, action: "replace", target: "questrade-providers-panel"+ assert_includes response.body, ERB::Util.html_escape("Refresh token can't be blank")+ end+# ---------------------------------------------------------------------------# update# ---------------------------------------------------------------------------@@ -68,6 +77,17 @@ class QuestradeItemsControllerTest < ActionDispatch::IntegrationTestassert_equal original_token, @questrade_item.refresh_tokenend+ # Redirecting back to Bank sync collapses the open connection row.+ test "update from the page re-renders the panel in place" do+ patch questrade_item_url(@questrade_item),+ params: { questrade_item: { name: "Renamed Questrade", refresh_token: "" } },+ as: :turbo_stream++ assert_turbo_stream action: "replace", target: "questrade-providers-panel"+ assert_includes response.body, %(id="questrade-providers-panel")+ assert_equal "Renamed Questrade", @questrade_item.reload.name+ end+# ---------------------------------------------------------------------------# destroy# ---------------------------------------------------------------------------diff --git a/test/controllers/redbark_items_controller_test.rb b/test/controllers/redbark_items_controller_test.rbindex 9f94d40dd2..57be0917e6 100644--- a/test/controllers/redbark_items_controller_test.rb+++ b/test/controllers/redbark_items_controller_test.rb@@ -34,6 +34,26 @@ class RedbarkItemsControllerTest < ActionDispatch::IntegrationTestendend+ test "invalid create from the page shows the error in the panel" do+ post redbark_items_url,+ params: { redbark_item: { api_key: "" } },+ as: :turbo_stream++ assert_turbo_stream status: :unprocessable_entity, action: "replace", target: "redbark-providers-panel"+ assert_includes response.body, ERB::Util.html_escape("Api key can't be blank")+ end++ # Redirecting back to Bank sync collapses the open connection row.+ test "update from the page re-renders the panel in place" do+ patch redbark_item_url(@redbark_item),+ params: { redbark_item: { name: "Renamed Redbark" } },+ as: :turbo_stream++ assert_turbo_stream action: "replace", target: "redbark-providers-panel"+ assert_includes response.body, %(id="redbark-providers-panel")+ assert_equal "Renamed Redbark", @redbark_item.reload.name+ end+test "update rotates the api key and clears requires_update" do@redbark_item.update!(status: :requires_update)diff --git a/test/controllers/settings/providers_controller_test.rb b/test/controllers/settings/providers_controller_test.rbindex 1f156190a7..ef7095f24e 100644--- a/test/controllers/settings/providers_controller_test.rb+++ b/test/controllers/settings/providers_controller_test.rb@@ -33,8 +33,8 @@ class Settings::ProvidersControllerTest < ActionDispatch::IntegrationTestassert_response :successassert_select "[data-provider-name='apple wallet']", count: 0- assert_select "turbo-frame#financekit-providers-panel" do- assert_select "a[href=?][data-turbo-frame='_top']", account_path(@source.account), text: "Test Wallet"+ assert_select "details#financekit-connection" do+ assert_select "a[href=?]", account_path(@source.account), text: "Test Wallet"assert_select "span", text: "Sync active"assert_select "dt", text: "Last accepted by Sure"assert_select "dt", text: "Last imported into your family"@@ -53,7 +53,7 @@ class Settings::ProvidersControllerTest < ActionDispatch::IntegrationTestget settings_providers_urlassert_response :success- assert_select "turbo-frame#financekit-providers-panel" do+ assert_select "details#financekit-connection" doassert_select "span", text: "Repair required — open the Sure iOS app"assert_select "dd", text: "Not yet", count: 2assert_select "a", text: "Test Wallet"@@ -68,7 +68,7 @@ class Settings::ProvidersControllerTest < ActionDispatch::IntegrationTestget settings_providers_urlassert_response :success- assert_select "turbo-frame#financekit-providers-panel", count: 0+ assert_select "details#financekit-connection", count: 0assert_select "[data-provider-name='apple wallet'] button[disabled]", text: "App Store"end@@ -84,7 +84,7 @@ class Settings::ProvidersControllerTest < ActionDispatch::IntegrationTestget settings_providers_urlassert_response :success- assert_select "turbo-frame#financekit-providers-panel"+ assert_select "details#financekit-connection"connections = @controller.view_assigns.values_at("connected", "needs_attention").flattenassert_equal [ "financekit" ], connections.map { |entry| entry[:provider_key] }assert_select "form[action=?]", sync_all_settings_providers_path, count: 0@@ -101,12 +101,12 @@ class Settings::ProvidersControllerTest < ActionDispatch::IntegrationTest@source.account.update!(status: "disabled")get settings_providers_urlassert_response :success- assert_select "turbo-frame#financekit-providers-panel a[href=?]", account_path(@source.account)+ assert_select "details#financekit-connection a[href=?]", account_path(@source.account)@source.account.update!(status: "pending_deletion")get settings_providers_urlassert_response :success- assert_select "turbo-frame#financekit-providers-panel", count: 0+ assert_select "details#financekit-connection", count: 0assert_select "a[href=?]", account_path(@source.account), count: 0assert_select "[data-provider-name='apple wallet']"end@@ -117,7 +117,7 @@ class Settings::ProvidersControllerTest < ActionDispatch::IntegrationTestget settings_providers_urlassert_response :success- assert_select "turbo-frame#financekit-providers-panel", count: 0+ assert_select "details#financekit-connection", count: 0assert_select "[data-provider-name='apple wallet']"end@@ -129,7 +129,7 @@ class Settings::ProvidersControllerTest < ActionDispatch::IntegrationTestget settings_providers_urlassert_response :success- assert_select "turbo-frame#financekit-providers-panel", count: 0+ assert_select "details#financekit-connection", count: 0assert_select "[data-provider-name='apple wallet']"end@@ -198,11 +198,37 @@ class Settings::ProvidersControllerTest < ActionDispatch::IntegrationTestassert_response :success%w[wise coinspot].each do |key|- assert_select "turbo-frame##{key}-providers-panel"+ assert_select "details##{key}-connection"assert_select "a[href=?]", connect_form_settings_providers_path(provider_key: key), count: 0endend+ # Row panels used to sit in a frame of their own. A redirect to a page+ # without that frame showed "Content missing", and a stream to+ # "<key>-providers-panel" replaced the frame when the two shared that id.+ test "connection rows post from the page and leave panel ids unique" do+ get settings_providers_url++ assert_response :success+ assert_operator css_select("details[id$='-connection']").size, :>, 1+ assert_select "details[id$='-connection'] turbo-frame", count: 0++ panel_ids = css_select("[id$='-providers-panel']").map { |element| element["id"] }+ assert_equal panel_ids.uniq, panel_ids+ end++ # Saves and errors from a row or the drawer re-render the panel by replacing+ # "<turbo_id>-providers-panel", and EnableBankingItem::SyncCompleteEvent does+ # the same when a sync finishes. SnapTrade never streams to it.+ test "every streamed panel renders the root its streams replace" do+ Settings::ProvidersController::FAMILY_PANELS.reject { |panel| panel[:key] == "snaptrade" }.each do |panel|+ get connect_form_settings_providers_url(provider_key: panel[:key])++ assert_response :success+ assert_select "##{panel[:turbo_id]}-providers-panel", 1, "#{panel[:key]} panel root"+ end+ end+test "lists Wise and CoinSpot as available when the family has no connections" dosign_in users(:empty)@@ -210,7 +236,7 @@ class Settings::ProvidersControllerTest < ActionDispatch::IntegrationTestassert_response :success%w[wise coinspot].each do |key|- assert_select "turbo-frame##{key}-providers-panel", count: 0+ assert_select "details##{key}-connection", count: 0assert_select "a[href=?]", connect_form_settings_providers_path(provider_key: key)endenddiff --git a/test/controllers/simplefin_items_controller_test.rb b/test/controllers/simplefin_items_controller_test.rbindex 23bde76085..98464eb7b1 100644--- a/test/controllers/simplefin_items_controller_test.rb+++ b/test/controllers/simplefin_items_controller_test.rb@@ -182,6 +182,39 @@ class SimplefinItemsControllerTest < ActionDispatch::IntegrationTestassert_includes response.body, I18n.t("simplefin_items.update.errors.blank_token", default: "Please enter a SimpleFIN setup token")end+ # The edit modal sits in turbo-frame#modal, so Turbo swaps in that frame from+ # the response. A stream aimed at the Bank sync panel left the modal as it was.+ test "invalid update from the edit modal shows the error in the modal" do+ @simplefin_item.update!(status: :requires_update)++ patch simplefin_item_url(@simplefin_item),+ params: { simplefin_item: { setup_token: "" } },+ headers: { "Turbo-Frame" => "modal" }++ assert_response :unprocessable_entity+ assert_select "turbo-frame#modal form[action=?]", simplefin_item_path(@simplefin_item)+ assert_select "turbo-frame#modal", text: /#{I18n.t("simplefin_items.update.errors.blank_token")}/+ end++ test "invalid create from the Bank sync panel shows the error in the panel" do+ post simplefin_items_url, params: { source: "panel", simplefin_item: { setup_token: "" } }, as: :turbo_stream++ assert_turbo_stream status: :unprocessable_entity, action: "replace", target: "simplefin-providers-panel"+ assert_includes response.body, I18n.t("simplefin_items.create.errors.blank_token")+ end++ # The new-connection modal posts to the top of the page, with the same Accept+ # header as the panel, and shows its error in its own template.+ test "invalid create from the new connection modal renders the modal with the error" do+ post simplefin_items_url,+ params: { simplefin_item: { setup_token: "" } },+ headers: { "Accept" => "text/vnd.turbo-stream.html, text/html, application/xhtml+xml" }++ assert_response :unprocessable_entity+ assert_select "turbo-frame#modal form[action=?]", simplefin_items_path+ assert_includes response.body, I18n.t("simplefin_items.create.errors.blank_token")+ end+test "should update simplefin item access_url in place preserving account linkages" do@simplefin_item.update!(status: :requires_update)original_item_id = @simplefin_item.iddiff --git a/test/controllers/sophtron_items_controller_test.rb b/test/controllers/sophtron_items_controller_test.rbindex 0ae7132a16..b24ddfb5d9 100644--- a/test/controllers/sophtron_items_controller_test.rb+++ b/test/controllers/sophtron_items_controller_test.rb@@ -181,6 +181,8 @@ class SophtronItemsControllerTest < ActionDispatch::IntegrationTestassert_equal "[FILTERED]", filtered_params[:captcha_input]end+ # The drawer and connection rows post from the page; a new connection still+ # moves on to accounts rather than re-rendering the panel.test "create verifies credentials and persists provisioned customer id" dostub_request(:get, "https://api.sophtron.com/api/Institution/HealthCheckAuth").to_return(status: 200, body: "")@@ -199,7 +201,7 @@ class SophtronItemsControllerTest < ActionDispatch::IntegrationTestuser_id: "developer-user",access_key: Base64.strict_encode64("secret-key")}- }+ }, as: :turbo_streamenditem = @user.family.sophtron_items.find_by!(name: "New Sophtron")@@ -207,6 +209,40 @@ class SophtronItemsControllerTest < ActionDispatch::IntegrationTestassert_redirected_to accounts_pathend+ test "invalid create outside a frame redirects instead of rendering a missing template" do+ assert_no_difference "SophtronItem.count" do+ post sophtron_items_url, params: { sophtron_item: { name: "New Sophtron", user_id: "", access_key: "" } }+ end++ assert_response :see_other+ assert_redirected_to settings_providers_path+ assert_match "can't be blank", flash[:alert]+ end++ test "invalid create from the page shows the error in the panel" do+ post sophtron_items_url,+ params: { sophtron_item: { name: "New Sophtron", user_id: "", access_key: "" } },+ as: :turbo_stream++ assert_turbo_stream status: :unprocessable_entity, action: "replace", target: "sophtron-providers-panel"+ assert_includes response.body, ERB::Util.html_escape("can't be blank")+ end++ # The connection row posts from the page. Leaving for Accounts closed the row+ # the save came from.+ test "update from the page re-renders the panel in place instead of leaving for accounts" do+ stub_request(:get, "https://api.sophtron.com/api/Institution/HealthCheckAuth")+ .to_return(status: 200, body: "")++ patch sophtron_item_url(@item),+ params: { sophtron_item: { name: "Renamed Sophtron" } },+ as: :turbo_stream++ assert_turbo_stream action: "replace", target: "sophtron-providers-panel"+ assert_includes response.body, %(id="sophtron-providers-panel")+ assert_equal "Renamed Sophtron", @item.reload.name+ end+test "connection_status renders MFA challenge when Sophtron asks for security answers" do@item.update!(user_institution_id: "ui-1", current_job_id: "job-1")provider = mockdiff --git a/test/controllers/trade_republic_items_controller_test.rb b/test/controllers/trade_republic_items_controller_test.rbindex d52634487a..c024acd652 100644--- a/test/controllers/trade_republic_items_controller_test.rb+++ b/test/controllers/trade_republic_items_controller_test.rb@@ -5,6 +5,26 @@ class TradeRepublicItemsControllerTest < ActionDispatch::IntegrationTestsign_in users(:family_admin)end+ # Redirecting back to Bank sync would collapse the open connection row. Only+ # this card is replaced, so the other cards keep their state.+ test "sync from the panel re-renders its card in place" do+ item = trade_republic_items(:configured_item)++ post sync_trade_republic_item_url(item, source: "panel"), as: :turbo_stream++ assert_turbo_stream action: "replace", target: TradeRepublic::ConnectionCardComponent.dom_id_for(item)+ assert_includes response.body, I18n.t("settings.providers.sync_provider_in_progress")+ assert item.reload.syncing?+ end++ # The Accounts page's Sync button posts here too, without the panel's source.+ test "sync from the Accounts page goes back to it" do+ post sync_trade_republic_item_url(trade_republic_items(:configured_item)),+ headers: { "Accept" => "text/vnd.turbo-stream.html, text/html, application/xhtml+xml", "Referer" => accounts_url }++ assert_redirected_to accounts_url+ end+test "create rejects a web login without a PIN before persisting the item" doassert_no_difference "TradeRepublicItem.count" dopost trade_republic_items_url, params: {@@ -29,7 +49,7 @@ class TradeRepublicItemsControllerTest < ActionDispatch::IntegrationTest}, headers: { "ACCEPT" => "text/vnd.turbo-stream.html" }end- assert_response :unprocessable_entity+ assert_turbo_stream status: :unprocessable_entity, action: "replace", target: "trade-republic-providers-panel"assert_includes response.body, I18n.t("trade_republic_items.initiate_login.pin_required")assert_select "input[name='trade_republic_item[phone_number]'][value='+491701234567']"enddiff --git a/test/controllers/trading212_controller_test.rb b/test/controllers/trading212_controller_test.rbindex 4d7979fca1..c7ffc91ab4 100644--- a/test/controllers/trading212_controller_test.rb+++ b/test/controllers/trading212_controller_test.rb@@ -45,10 +45,10 @@ class Trading212ItemsControllerTest < ActionDispatch::IntegrationTestapi_secret: "",environment: "live"}- }, headers: { "Turbo-Frame" => "modal" }+ }, as: :turbo_streamend- assert_response :unprocessable_entity+ assert_turbo_stream status: :unprocessable_entity, action: "replace", target: "trading212-providers-panel"end# === update ===@@ -66,6 +66,16 @@ class Trading212ItemsControllerTest < ActionDispatch::IntegrationTestassert_equal "demo", @item.reload.environmentend+ test "update from the page re-renders the panel in place instead of leaving for accounts" do+ patch trading212_item_url(@item),+ params: { trading212_item: { api_key: "", api_secret: "", environment: "demo" } },+ as: :turbo_stream++ assert_turbo_stream action: "replace", target: "trading212-providers-panel"+ assert_includes response.body, %(id="trading212-providers-panel")+ assert_equal "demo", @item.reload.environment+ end+# === destroy ===test "destroy schedules item for deletion" do@@ -86,6 +96,15 @@ class Trading212ItemsControllerTest < ActionDispatch::IntegrationTestassert_response :redirectend+ # Redirecting back to Bank sync would collapse the open connection row.+ test "sync from the panel re-renders the panel in place" do+ post sync_trading212_item_url(@item, source: "panel"), as: :turbo_stream++ assert_turbo_stream action: "replace", target: "trading212-providers-panel"+ assert_includes response.body, I18n.t("settings.providers.sync_provider_in_progress")+ assert @item.reload.syncing?+ end+# === complete_account_setup ===test "complete_account_setup creates investment account and provider link" dodiff --git a/test/controllers/up_items_controller_test.rb b/test/controllers/up_items_controller_test.rbnew file mode 100644index 0000000000..2fe01afb8a--- /dev/null+++ b/test/controllers/up_items_controller_test.rb@@ -0,0 +1,61 @@+require "test_helper"++class UpItemsControllerTest < ActionDispatch::IntegrationTest+ setup do+ sign_in users(:family_admin)+ SyncJob.stubs(:perform_later)++ @up_item = UpItem.create!(+ family: families(:dylan_family),+ name: "Main Up",+ access_token: "up-personal-token"+ )+ end++ # Redirecting back to Bank sync would collapse the open connection row.+ test "sync from the panel re-renders the panel in place" do+ post sync_up_item_url(@up_item, source: "panel"), as: :turbo_stream++ assert_turbo_stream action: "replace", target: "up-providers-panel"+ assert_includes response.body, I18n.t("settings.providers.sync_provider_in_progress")+ assert @up_item.reload.syncing?+ end++ # The Accounts page's Sync button posts here too, without the panel's source.+ test "sync from the Accounts page goes back to it" do+ post sync_up_item_url(@up_item),+ headers: { "Accept" => "text/vnd.turbo-stream.html, text/html, application/xhtml+xml", "Referer" => accounts_url }++ assert_redirected_to accounts_url+ end++ # Redirecting back to Bank sync collapses the open connection row.+ test "update from the page re-renders the panel in place" do+ patch up_item_url(@up_item),+ params: { up_item: { name: "Renamed Up", access_token: "" } },+ as: :turbo_stream++ assert_turbo_stream action: "replace", target: "up-providers-panel"+ assert_includes response.body, %(id="up-providers-panel")+ assert_equal "Renamed Up", @up_item.reload.name+ assert_equal "up-personal-token", @up_item.access_token+ end++ test "invalid create from the page shows the error in the panel" do+ post up_items_url,+ params: { up_item: { name: "Second Up", access_token: "" } },+ as: :turbo_stream++ assert_turbo_stream status: :unprocessable_entity, action: "replace", target: "up-providers-panel"+ assert_includes response.body, ERB::Util.html_escape("Access token can't be blank")+ end++ # The new connection belongs in Your connections, so the page reloads.+ test "create from the page still reloads Bank sync" do+ post up_items_url,+ params: { up_item: { name: "Second Up", access_token: "another-token" } },+ as: :turbo_stream++ assert_redirected_to settings_providers_path+ end+enddiff --git a/test/controllers/wise_items_controller_test.rb b/test/controllers/wise_items_controller_test.rbindex 2a3d9a16ac..f0647fbe86 100644--- a/test/controllers/wise_items_controller_test.rb+++ b/test/controllers/wise_items_controller_test.rb@@ -14,6 +14,23 @@ class WiseItemsControllerTest < ActionDispatch::IntegrationTest]end+ # Redirecting back to Bank sync would collapse the open connection row.+ test "sync from the panel re-renders the panel in place" do+ post sync_wise_item_url(@wise_item, source: "panel"), as: :turbo_stream++ assert_turbo_stream action: "replace", target: "wise-providers-panel"+ assert_includes response.body, I18n.t("settings.providers.sync_provider_in_progress")+ assert @wise_item.reload.syncing?+ end++ # The Accounts page's Sync button posts here too, without the panel's source.+ test "sync from the Accounts page goes back to it" do+ post sync_wise_item_url(@wise_item),+ headers: { "Accept" => "text/vnd.turbo-stream.html, text/html, application/xhtml+xml", "Referer" => accounts_url }++ assert_redirected_to accounts_url+ end+# create redirects to select_profiles (Turbo requires a redirect from a standard# form submission) — the encrypted token travels via the session, not the response body.@@ -50,6 +67,15 @@ class WiseItemsControllerTest < ActionDispatch::IntegrationTestassert_nil session[:wise_pending_token]end+ test "create from the drawer shows a blank token error in the panel" do+ post wise_items_url,+ params: { wise_item: { token: "" } },+ as: :turbo_stream++ assert_turbo_stream status: :unprocessable_entity, action: "replace", target: "wise-providers-panel"+ assert_includes response.body, ERB::Util.html_escape("Token can't be blank")+ end+test "create redirects to providers when Wise API rejects the token" doProvider::Wise.any_instance.stubs(:get_profiles).raises(Provider::Wise::WiseError.new("unauthorized", :unauthorized)@@ -132,6 +158,26 @@ class WiseItemsControllerTest < ActionDispatch::IntegrationTestassert @wise_item.reload.sca_configured?end+ test "generate_sca_keypair from the page shows the new public key in place" do+ WiseItem.any_instance.stubs(:sca_encryption_available?).returns(true)++ post generate_sca_keypair_wise_item_url(@wise_item),+ as: :turbo_stream++ assert_turbo_stream action: "replace", target: "wise-providers-panel"+ assert_includes response.body, %(id="wise-providers-panel")+ assert_includes response.body, @wise_item.reload.sca_public_key.lines.second.strip+ end++ test "update from the page re-renders the panel in place instead of leaving for accounts" do+ patch wise_item_url(@wise_item),+ params: { wise_item: { name: "Renamed Wise" } },+ as: :turbo_stream++ assert_turbo_stream action: "replace", target: "wise-providers-panel"+ assert_equal "Renamed Wise", @wise_item.reload.name+ end+test "generate_sca_keypair replaces a previously generated keypair" doWiseItem.any_instance.stubs(:sca_encryption_available?).returns(true)diff --git a/test/lib/generators/provider/family_generator_test.rb b/test/lib/generators/provider/family_generator_test.rbindex 4abd5227f8..8493a6356d 100644--- a/test/lib/generators/provider/family_generator_test.rb+++ b/test/lib/generators/provider/family_generator_test.rb@@ -16,10 +16,14 @@ class Provider::FamilyGeneratorTest < ActiveSupport::TestCaseflunk "generated invalid Ruby: #{e.message}\n\n#{source}"end+ def render_template(name, **locals)+ template = Rails.root.join("lib/generators/provider/family/templates", name).read+ context = Struct.new(*locals.keys).new(*locals.values)+ ERB.new(template, trim_mode: "-").result(context.instance_eval { binding })+ end+test "the unlinking scaffold renders to valid Ruby and carries the disposition seam" do- template = Rails.root.join("lib/generators/provider/family/templates/unlinking_concern.rb.tt").read- context = Struct.new(:class_name, :file_name).new("Gocardless", "gocardless")- rendered = ERB.new(template, trim_mode: "-").result(context.instance_eval { binding })+ rendered = render_template("unlinking_concern.rb.tt", class_name: "Gocardless", file_name: "gocardless")assert_parses rendered# A generated provider retains by default and refuses a discard it has not@@ -107,6 +111,88 @@ class Provider::FamilyGeneratorTest < ActiveSupport::TestCaseassert_includes result, "pl\\\\aid"end+ # Row and drawer forms post from the page, so no request carries a Turbo-Frame+ # header: saves and errors stream into the panel, and a new connection reloads.+ test "the controller scaffold renders to valid Ruby and answers panel requests in place" do+ rendered = render_template("controller.rb.tt", class_name: "Gocardless", file_name: "gocardless",+ table_name: "gocardless_items", parsed_fields: [ { name: "secret_id" } ])++ assert_parses rendered+ assert_not_includes rendered, "turbo_frame_request?"+ assert_includes rendered, %(render_provider_panel("gocardless", alert: @gocardless_item.errors.full_messages.join(", ")))+ assert_includes rendered, 'render_provider_panel("gocardless", notice: t(".success"'+ assert_match(/if @gocardless_item\.save\n\s+redirect_to settings_providers_path, notice:/, rendered)+ end++ # Bank sync builds its connection rows and drawers from FAMILY_PANELS, so a+ # section injected into show.html.erb would render outside both.+ test "adds the provider to the family panels of the real providers controller" do+ source = Rails.root.join("app/controllers/settings/providers_controller.rb").read+ result = Provider::FamilyGenerator.append_family_panel_entry(source, key: "gocardless", title: "Gocardless")++ assert_parses result+ assert_includes result, %( { key: "gocardless", title: "Gocardless", turbo_id: "gocardless", partial: "gocardless_panel" }\n ].freeze)+ end++ test "separates the new family panel from the previous last entry" do+ result = Provider::FamilyGenerator.append_family_panel_entry(<<~RUBY, key: "gocardless", title: "Gocardless")+ FAMILY_PANELS = [+ { key: "akahu", title: "Akahu", turbo_id: "akahu", partial: "akahu_panel" }+ ].freeze+ RUBY++ assert_parses result+ assert_includes result, %(partial: "akahu_panel" },\n { key: "gocardless")+ end++ test "returns nil when there are no family panels to update" do+ assert_nil Provider::FamilyGenerator.append_family_panel_entry("class Foo\nend\n", key: "gocardless", title: "Gocardless")+ end++ # provider_summary leaves a key it doesn't know under Available, so a connected+ # provider only moves to Your connections through its own case.+ test "adds a provider_summary case to the real settings helper" do+ source = Rails.root.join("app/helpers/settings_helper.rb").read+ result = Provider::FamilyGenerator.append_provider_summary_case(source, key: "gocardless")++ assert_parses result+ assert_includes result[/def provider_summary\b.*?\n end\n/m],+ %( when "gocardless"\n return { status: :off } unless @gocardless_items&.any?\n sync_based_summary(key)\n else\n { status: :off }\n)+ end++ test "returns nil when there is no provider_summary to update" do+ assert_nil Provider::FamilyGenerator.append_provider_summary_case("module Foo\nend\n", key: "gocardless")+ end++ # The row's sync status reads both maps, and its Sync button posts a key that+ # Settings::ProvidersController#sync looks up in PANEL_SYNCABLE_TYPES.+ test "adds the provider to the sync maps of the real providers controller" do+ source = Rails.root.join("app/controllers/settings/providers_controller.rb").read+ result = Provider::FamilyGenerator.append_panel_syncable_type(source, key: "gocardless", class_name: "Gocardless")+ result = Provider::FamilyGenerator.append_family_panel_item(result, key: "gocardless")++ assert_parses result+ syncable = result[/PANEL_SYNCABLE_TYPES = \{\n(.*?)\n\s*\}\.freeze/m, 1].lines(chomp: true)+ items = result[/def family_panel_items\n\s*\{\n(.*?)\n\s*\}\n/m, 1].lines(chomp: true)++ assert_equal %("gocardless" => "GocardlessItem"), syncable.last.squish+ assert_equal %("gocardless" => @gocardless_items), items.last.squish+ # The arrows line up with the entry above, however long the longest key is.+ assert_equal syncable[-2].index("=>"), syncable.last.index("=>")+ assert_equal items[-2].index("=>"), items.last.index("=>")+ end++ test "keeps a space before the arrow when the new key is longer than the column" do+ result = Provider::FamilyGenerator.append_panel_syncable_type(<<~RUBY, key: "gocardless_bank_data", class_name: "GocardlessBankData")+ PANEL_SYNCABLE_TYPES = {+ "up" => "UpItem"+ }.freeze+ RUBY++ assert_parses result+ assert_includes result, %( "up" => "UpItem",\n "gocardless_bank_data" => "GocardlessBankDataItem"\n}.freeze)+ end+test "reserved item columns exclude family but include family_id" do# family is created by t.references :family as family_id, so a field named family is# not a collision and must not be rejected.diff --git a/test/system/settings/providers_test.rb b/test/system/settings/providers_test.rbindex af209026e9..196aae181f 100644--- a/test/system/settings/providers_test.rb+++ b/test/system/settings/providers_test.rb@@ -16,7 +16,7 @@ class Settings::ProvidersTest < ApplicationSystemTestCasevisit settings_providers_pathfind("summary", text: "Apple Wallet").clickfind("details", text: "Apple Wallet").native.save_screenshot(Rails.root.join("tmp", "apple-wallet-connected.png"))- within "turbo-frame#financekit-providers-panel" do+ within "details#financekit-connection" doclick_link "Test Wallet"end@@ -32,6 +32,53 @@ class Settings::ProvidersTest < ApplicationSystemTestCaseassert_text "Synthetic shop"end+ test "disconnecting from a connection row follows the redirect and shows its flash" do+ item = mercury_items(:one)++ visit settings_providers_path+ find("summary", text: "Mercury").click+ find("summary", text: item.name).click+ find("form[action='#{mercury_item_path(item)}']:has(input[name='_method'][value='delete']) button").click+ within("#confirm-dialog") { click_button "Confirm" }++ assert_current_path accounts_path+ assert_text I18n.t("mercury_items.destroy.success")+ end++ test "saving a connection from its row stays on the page for the next save" do+ item = mercury_items(:one)++ visit settings_providers_path+ find("summary", text: "Mercury").click++ [ "Renamed Mercury", "Renamed Mercury again" ].each do |name|+ find("summary", text: item.reload.name).click+ within("form[action='#{mercury_item_path(item)}']:has(input[name='_method'][value='patch'])") do+ fill_in I18n.t("mercury_items.provider_panel.connection_name_label"), with: name+ click_button I18n.t("mercury_items.provider_panel.update_connection")+ end++ assert_selector "summary", text: name+ assert_current_path settings_providers_path+ end+ assert_equal "Renamed Mercury again", item.reload.name+ end++ test "syncing a connection from its row keeps the row open" do+ item = mercury_items(:one)++ visit settings_providers_path+ find("summary", text: "Mercury").click+ find("summary", text: item.name).click+ find("form[action='#{sync_mercury_item_path(item, source: "panel")}'] button").click++ # The toast arrives in the same stream as the panel, after it.+ assert_text I18n.t("settings.providers.sync_provider_in_progress")+ assert_selector "details#mercury-connection[open]"+ assert_current_path settings_providers_path+ assert item.reload.syncing?+ end+test "Wallet advertises App Store availability without a web connection flow" dovisit settings_providers_pathfind('[data-providers-filter-target="input"]').set("Apple Wallet")