The personal finance app for everyone (by everyone)
Ruby
Stop broadcasting provider cards to the whole family (#4046)
jaysbeekaybdb280b3bd96
diff --git a/app/jobs/indexa_capital_activities_fetch_job.rb b/app/jobs/indexa_capital_activities_fetch_job.rbindex 2b355aea2f..58768ad4e6 100644--- a/app/jobs/indexa_capital_activities_fetch_job.rb+++ b/app/jobs/indexa_capital_activities_fetch_job.rb@@ -30,11 +30,9 @@ class IndexaCapitalActivitiesFetchJob < ApplicationJobdef broadcast_updates@indexa_capital_account.current_account&.broadcast_sync_complete- @indexa_capital_account.indexa_capital_item&.broadcast_replace_to(- @indexa_capital_account.indexa_capital_item.family,- target: "indexa_capital_item_#{@indexa_capital_account.indexa_capital_item.id}",- partial: "indexa_capital_items/indexa_capital_item"- )+ # Not the rendered card, which lists every account on the connection and+ # has no viewer to filter for here (#3630); the toast re-fetches per viewer.+ @indexa_capital_account.indexa_capital_item&.family&.broadcast_sync_completerescue => eRails.logger.warn("IndexaCapitalActivitiesFetchJob - Broadcast failed: #{e.message}")enddiff --git a/app/jobs/questrade_activities_fetch_job.rb b/app/jobs/questrade_activities_fetch_job.rbindex 26337a4248..7729425f08 100644--- a/app/jobs/questrade_activities_fetch_job.rb+++ b/app/jobs/questrade_activities_fetch_job.rb@@ -120,11 +120,9 @@ class QuestradeActivitiesFetchJob < ApplicationJobdef broadcast_updates@questrade_account.current_account&.broadcast_sync_complete- @questrade_account.questrade_item&.broadcast_replace_to(- @questrade_account.questrade_item.family,- target: "questrade_item_#{@questrade_account.questrade_item.id}",- partial: "questrade_items/questrade_item"- )+ # Not the rendered card, which lists every account on the connection and+ # has no viewer to filter for here (#3630); the toast re-fetches per viewer.+ @questrade_account.questrade_item&.family&.broadcast_sync_completerescue => eRails.logger.warn("QuestradeActivitiesFetchJob - Broadcast failed: #{e.message}")enddiff --git a/app/jobs/simplefin_item/balances_only_job.rb b/app/jobs/simplefin_item/balances_only_job.rbindex 17f15c87c3..8853a53880 100644--- a/app/jobs/simplefin_item/balances_only_job.rb+++ b/app/jobs/simplefin_item/balances_only_job.rb@@ -23,19 +23,11 @@ class SimplefinItem::BalancesOnlyJob < ApplicationJob# Leaving last_synced_at nil ensures the next full sync uses the# chunked-history path to fetch historical transactions.- # Refresh the SimpleFin card on Providers/Accounts pages so badges and statuses update without a full reload+ # Refresh Providers/Accounts pages so badges and statuses update without a manual reloadbegin- card_html = ApplicationController.render(- partial: "simplefin_items/simplefin_item",- formats: [ :html ],- locals: { simplefin_item: item }- )- target_id = ActionView::RecordIdentifier.dom_id(item)- Turbo::StreamsChannel.broadcast_replace_to(item.family, target: target_id, html: card_html)-# Broadcast a refresh signal instead of rendered HTML. Each user's browser# re-fetches via their own authenticated request, so the manual accounts- # list is correctly scoped to the current user.+ # list and the SimpleFIN card are scoped to the current user (#3630).item.family.broadcast_refreshrescue => eRails.logger.warn("SimpleFin BalancesOnlyJob broadcast failed: #{e.class} - #{e.message}")diff --git a/app/models/akahu_item/sync_complete_event.rb b/app/models/akahu_item/sync_complete_event.rbindex 73fed67a18..717c185291 100644--- a/app/models/akahu_item/sync_complete_event.rb+++ b/app/models/akahu_item/sync_complete_event.rb@@ -8,13 +8,6 @@ class AkahuItem::SyncCompleteEventdef broadcastakahu_item.accounts.each(&:broadcast_sync_complete)- akahu_item.broadcast_replace_to(- akahu_item.family,- target: "akahu_item_#{akahu_item.id}",- partial: "akahu_items/akahu_item",- locals: { akahu_item: akahu_item }- )-akahu_item.family.broadcast_sync_completeendenddiff --git a/app/models/binance_item/sync_complete_event.rb b/app/models/binance_item/sync_complete_event.rbindex d76449a91e..4de93c32c7 100644--- a/app/models/binance_item/sync_complete_event.rb+++ b/app/models/binance_item/sync_complete_event.rb@@ -17,14 +17,6 @@ class BinanceItem::SyncCompleteEventaccount.broadcast_sync_completeend- # Update the Binance item view- binance_item.broadcast_replace_to(- binance_item.family,- target: "binance_item_#{binance_item.id}",- partial: "binance_items/binance_item",- locals: { binance_item: binance_item }- )-# Let family handle sync notificationsbinance_item.family.broadcast_sync_completeenddiff --git a/app/models/coinbase_item/sync_complete_event.rb b/app/models/coinbase_item/sync_complete_event.rbindex 05dac5fe2e..ef1d485831 100644--- a/app/models/coinbase_item/sync_complete_event.rb+++ b/app/models/coinbase_item/sync_complete_event.rb@@ -15,14 +15,6 @@ class CoinbaseItem::SyncCompleteEventaccount.broadcast_sync_completeend- # Update the Coinbase item view- coinbase_item.broadcast_replace_to(- coinbase_item.family,- target: "coinbase_item_#{coinbase_item.id}",- partial: "coinbase_items/coinbase_item",- locals: { coinbase_item: coinbase_item }- )-# Let family handle sync notificationscoinbase_item.family.broadcast_sync_completeenddiff --git a/app/models/coinspot_item/sync_complete_event.rb b/app/models/coinspot_item/sync_complete_event.rbindex 396b10db5b..2338d7d543 100644--- a/app/models/coinspot_item/sync_complete_event.rb+++ b/app/models/coinspot_item/sync_complete_event.rb@@ -10,16 +10,14 @@ class CoinspotItem::SyncCompleteEvent@coinspot_item = coinspot_itemend- # Turbo-broadcasts a re-render of this connection's card so its sync- # status updates live in the browser without a page reload. Logs and- # swallows failures -- a broadcast issue shouldn't fail the sync itself.+ # Tells the family's browsers the sync finished, so each re-fetches the page+ # with its own permissions. Logs and swallows failures -- a broadcast issue+ # shouldn't fail the sync itself.def broadcast- Turbo::StreamsChannel.broadcast_replace_to(- @coinspot_item.family,- target: ActionView::RecordIdentifier.dom_id(@coinspot_item),- partial: "coinspot_items/coinspot_item",- locals: { coinspot_item: @coinspot_item }- )+ # Not the rendered card: it lists every account on the connection and a+ # broadcast has no viewer to filter for (#3630). The toast re-fetches the+ # page per viewer.+ @coinspot_item.family.broadcast_sync_completerescue StandardError => eRails.logger.warn("CoinspotItem::SyncCompleteEvent failed for #{@coinspot_item.id}: #{e.class}")enddiff --git a/app/models/coinstats_item/sync_complete_event.rb b/app/models/coinstats_item/sync_complete_event.rbindex dfd6f5f8c0..05d82edc24 100644--- a/app/models/coinstats_item/sync_complete_event.rb+++ b/app/models/coinstats_item/sync_complete_event.rb@@ -15,14 +15,6 @@ class CoinstatsItem::SyncCompleteEventaccount.broadcast_sync_completeend- # Update the CoinStats item view- coinstats_item.broadcast_replace_to(- coinstats_item.family,- target: "coinstats_item_#{coinstats_item.id}",- partial: "coinstats_items/coinstats_item",- locals: { coinstats_item: coinstats_item }- )-# Let family handle sync notificationscoinstats_item.family.broadcast_sync_completeenddiff --git a/app/models/enable_banking_item/sync_complete_event.rb b/app/models/enable_banking_item/sync_complete_event.rbindex 9cb14f2fc6..c1cfe78d88 100644--- a/app/models/enable_banking_item/sync_complete_event.rb+++ b/app/models/enable_banking_item/sync_complete_event.rb@@ -16,17 +16,11 @@ class EnableBankingItem::SyncCompleteEventfamily = enable_banking_item.familyreturn unless family- # Update the Enable Banking item view on the Accounts page- enable_banking_item.broadcast_replace_to(- family,- target: "enable_banking_item_#{enable_banking_item.id}",- partial: "enable_banking_items/enable_banking_item",- locals: { enable_banking_item: enable_banking_item }- )-- # The Settings > Providers panel is not streamed here: it is admin-only and- # holds the connection's credentials, and every family member subscribes to- # this stream. The sync toast below makes each browser re-fetch its own page.+ # Neither the connection card nor the Settings > Providers panel is+ # streamed here: every family member subscribes to this stream, the card+ # lists every account on the connection, and the panel is admin-only and+ # holds the connection's credentials. The sync toast below makes each+ # browser re-fetch its own page.# Let family handle sync notificationsfamily.broadcast_sync_completediff --git a/app/models/fio_item/sync_complete_event.rb b/app/models/fio_item/sync_complete_event.rbindex 509aac343f..23828a484b 100644--- a/app/models/fio_item/sync_complete_event.rb+++ b/app/models/fio_item/sync_complete_event.rb@@ -11,13 +11,6 @@ class FioItem::SyncCompleteEventdef broadcastfio_item.accounts.each(&:broadcast_sync_complete)- fio_item.broadcast_replace_to(- fio_item.family,- target: "fio_item_#{fio_item.id}",- partial: "fio_items/fio_item",- locals: { fio_item: fio_item }- )-fio_item.family.broadcast_sync_completeendenddiff --git a/app/models/ibkr_item/sync_complete_event.rb b/app/models/ibkr_item/sync_complete_event.rbindex 46ebe39ac2..ce24e9dc39 100644--- a/app/models/ibkr_item/sync_complete_event.rb+++ b/app/models/ibkr_item/sync_complete_event.rb@@ -10,13 +10,6 @@ class IbkrItem::SyncCompleteEventaccount.broadcast_sync_completeend- ibkr_item.broadcast_replace_to(- ibkr_item.family,- target: "ibkr_item_#{ibkr_item.id}",- partial: "ibkr_items/ibkr_item",- locals: { ibkr_item: ibkr_item }- )-ibkr_item.family.broadcast_sync_completeendenddiff --git a/app/models/indexa_capital_item/sync_complete_event.rb b/app/models/indexa_capital_item/sync_complete_event.rbindex 1033151320..32ce52c69b 100644--- a/app/models/indexa_capital_item/sync_complete_event.rb+++ b/app/models/indexa_capital_item/sync_complete_event.rb@@ -10,13 +10,6 @@ class IndexaCapitalItem::SyncCompleteEventaccount.broadcast_sync_completeend- indexa_capital_item.broadcast_replace_to(- indexa_capital_item.family,- target: "indexa_capital_item_#{indexa_capital_item.id}",- partial: "indexa_capital_items/indexa_capital_item",- locals: { indexa_capital_item: indexa_capital_item }- )-indexa_capital_item.family.broadcast_sync_completeendenddiff --git a/app/models/kraken_item/sync_complete_event.rb b/app/models/kraken_item/sync_complete_event.rbindex a2b07d69e9..b4fea54be0 100644--- a/app/models/kraken_item/sync_complete_event.rb+++ b/app/models/kraken_item/sync_complete_event.rb@@ -8,12 +8,10 @@ class KrakenItem::SyncCompleteEventenddef broadcast- Turbo::StreamsChannel.broadcast_replace_to(- @kraken_item.family,- target: ActionView::RecordIdentifier.dom_id(@kraken_item),- partial: "kraken_items/kraken_item",- locals: { kraken_item: @kraken_item }- )+ # Not the rendered card: it lists every account on the connection and a+ # broadcast has no viewer to filter for (#3630). The toast re-fetches the+ # page per viewer.+ @kraken_item.family.broadcast_sync_completerescue StandardError => eRails.logger.warn("KrakenItem::SyncCompleteEvent failed for #{@kraken_item.id}: #{e.class}")enddiff --git a/app/models/lunchflow_item/sync_complete_event.rb b/app/models/lunchflow_item/sync_complete_event.rbindex 0a33c27144..fce40803ea 100644--- a/app/models/lunchflow_item/sync_complete_event.rb+++ b/app/models/lunchflow_item/sync_complete_event.rb@@ -11,14 +11,6 @@ class LunchflowItem::SyncCompleteEventaccount.broadcast_sync_completeend- # Update the Lunchflow item view- lunchflow_item.broadcast_replace_to(- lunchflow_item.family,- target: "lunchflow_item_#{lunchflow_item.id}",- partial: "lunchflow_items/lunchflow_item",- locals: { lunchflow_item: lunchflow_item }- )-# Let family handle sync notificationslunchflow_item.family.broadcast_sync_completeenddiff --git a/app/models/mercury_item/sync_complete_event.rb b/app/models/mercury_item/sync_complete_event.rbindex 056297b662..c1a37e9aa2 100644--- a/app/models/mercury_item/sync_complete_event.rb+++ b/app/models/mercury_item/sync_complete_event.rb@@ -11,14 +11,6 @@ class MercuryItem::SyncCompleteEventaccount.broadcast_sync_completeend- # Update the Mercury item view- mercury_item.broadcast_replace_to(- mercury_item.family,- target: "mercury_item_#{mercury_item.id}",- partial: "mercury_items/mercury_item",- locals: { mercury_item: mercury_item }- )-# Let family handle sync notificationsmercury_item.family.broadcast_sync_completeenddiff --git a/app/models/monobank_item/sync_complete_event.rb b/app/models/monobank_item/sync_complete_event.rbindex 660f33f1bd..2e354d55a0 100644--- a/app/models/monobank_item/sync_complete_event.rb+++ b/app/models/monobank_item/sync_complete_event.rb@@ -10,13 +10,6 @@ class MonobankItem::SyncCompleteEventdef broadcastmonobank_item.accounts.each(&:broadcast_sync_complete)- monobank_item.broadcast_replace_to(- monobank_item.family,- target: "monobank_item_#{monobank_item.id}",- partial: "monobank_items/monobank_item",- locals: { monobank_item: monobank_item }- )-monobank_item.family.broadcast_sync_completeendenddiff --git a/app/models/onchain_wallet_item/sync_complete_event.rb b/app/models/onchain_wallet_item/sync_complete_event.rbindex c5e3e11f47..cf53358a47 100644--- a/app/models/onchain_wallet_item/sync_complete_event.rb+++ b/app/models/onchain_wallet_item/sync_complete_event.rb@@ -6,12 +6,10 @@ class OnchainWalletItem::SyncCompleteEventenddef broadcast- Turbo::StreamsChannel.broadcast_replace_to(- @onchain_wallet_item.family,- target: ActionView::RecordIdentifier.dom_id(@onchain_wallet_item),- partial: "onchain_wallet_items/onchain_wallet_item",- locals: { onchain_wallet_item: @onchain_wallet_item }- )+ # Not the rendered wallet row: it names every address on the connection+ # and a broadcast has no viewer to filter for (#3630). The toast re-fetches+ # the page per viewer.+ @onchain_wallet_item.family.broadcast_sync_completerescue StandardError => eRails.logger.warn("OnchainWalletItem::SyncCompleteEvent failed for #{@onchain_wallet_item.id}: #{e.class}")enddiff --git a/app/models/plaid_item/sync_complete_event.rb b/app/models/plaid_item/sync_complete_event.rbindex ca008a0ac3..d381f34028 100644--- a/app/models/plaid_item/sync_complete_event.rb+++ b/app/models/plaid_item/sync_complete_event.rb@@ -10,13 +10,6 @@ class PlaidItem::SyncCompleteEventaccount.broadcast_sync_completeend- plaid_item.broadcast_replace_to(- plaid_item.family,- target: "plaid_item_#{plaid_item.id}",- partial: "plaid_items/plaid_item",- locals: { plaid_item: plaid_item }- )-plaid_item.family.broadcast_sync_completeendenddiff --git a/app/models/redbark_item/sync_complete_event.rb b/app/models/redbark_item/sync_complete_event.rbindex 0049f8ffd7..b96b028983 100644--- a/app/models/redbark_item/sync_complete_event.rb+++ b/app/models/redbark_item/sync_complete_event.rb@@ -11,14 +11,6 @@ class RedbarkItem::SyncCompleteEventaccount.broadcast_sync_completeend- # Update the Redbark item view- redbark_item.broadcast_replace_to(- redbark_item.family,- target: "redbark_item_#{redbark_item.id}",- partial: "redbark_items/redbark_item",- locals: { redbark_item: redbark_item }- )-# Let family handle sync notificationsredbark_item.family.broadcast_sync_completeenddiff --git a/app/models/simplefin_item/sync_complete_event.rb b/app/models/simplefin_item/sync_complete_event.rbindex 315e89946a..fed1a1fae7 100644--- a/app/models/simplefin_item/sync_complete_event.rb+++ b/app/models/simplefin_item/sync_complete_event.rb@@ -11,14 +11,6 @@ class SimplefinItem::SyncCompleteEventaccount.broadcast_sync_completeend- # Update the SimpleFin item view- simplefin_item.broadcast_replace_to(- simplefin_item.family,- target: "simplefin_item_#{simplefin_item.id}",- partial: "simplefin_items/simplefin_item",- locals: { simplefin_item: simplefin_item }- )-# Let family handle sync notificationssimplefin_item.family.broadcast_sync_completeenddiff --git a/app/models/simplefin_item/syncer.rb b/app/models/simplefin_item/syncer.rbindex b8e1846536..fc5d32499b 100644--- a/app/models/simplefin_item/syncer.rb+++ b/app/models/simplefin_item/syncer.rb@@ -181,18 +181,9 @@ class SimplefinItem::Syncer# Broadcast UI updates so Providers/Accounts pages refresh without manual reloadbegin- # Replace the SimpleFin card- card_html = ApplicationController.render(- partial: "simplefin_items/simplefin_item",- formats: [ :html ],- locals: { simplefin_item: simplefin_item }- )- target_id = ActionView::RecordIdentifier.dom_id(simplefin_item)- Turbo::StreamsChannel.broadcast_replace_to(simplefin_item.family, target: target_id, html: card_html)-# Broadcast a refresh signal instead of rendered HTML. Each user's browser# re-fetches via their own authenticated request, so the manual accounts- # list is correctly scoped to the current user.+ # list and the SimpleFIN card are scoped to the current user (#3630).simplefin_item.family.broadcast_refreshrescue => eRails.logger.warn("SimplefinItem::Syncer broadcast failed: #{e.class} - #{e.message}")diff --git a/app/models/snaptrade_item/sync_complete_event.rb b/app/models/snaptrade_item/sync_complete_event.rbindex 647c32af83..2bbafadf42 100644--- a/app/models/snaptrade_item/sync_complete_event.rb+++ b/app/models/snaptrade_item/sync_complete_event.rb@@ -11,14 +11,6 @@ class SnaptradeItem::SyncCompleteEventaccount.broadcast_sync_completeend- # Update the SnapTrade item view- snaptrade_item.broadcast_replace_to(- snaptrade_item.family,- target: "snaptrade_item_#{snaptrade_item.id}",- partial: "snaptrade_items/snaptrade_item",- locals: { snaptrade_item: snaptrade_item }- )-# Let family handle sync notificationssnaptrade_item.family.broadcast_sync_completeenddiff --git a/app/models/sophtron_item/sync_complete_event.rb b/app/models/sophtron_item/sync_complete_event.rbindex 9bb83089c8..5775e140be 100644--- a/app/models/sophtron_item/sync_complete_event.rb+++ b/app/models/sophtron_item/sync_complete_event.rb@@ -11,14 +11,6 @@ class SophtronItem::SyncCompleteEventaccount.broadcast_sync_completeend- # Update the Sophtron item view- sophtron_item.broadcast_replace_to(- sophtron_item.family,- target: "sophtron_item_#{sophtron_item.id}",- partial: "sophtron_items/sophtron_item",- locals: { sophtron_item: sophtron_item }- )-# Let family handle sync notificationssophtron_item.family.broadcast_sync_completeenddiff --git a/app/models/trade_republic_item/sync_complete_event.rb b/app/models/trade_republic_item/sync_complete_event.rbindex a332e67310..c1d186f0d8 100644--- a/app/models/trade_republic_item/sync_complete_event.rb+++ b/app/models/trade_republic_item/sync_complete_event.rb@@ -10,13 +10,6 @@ class TradeRepublicItem::SyncCompleteEventaccount.broadcast_sync_completeend- trade_republic_item.broadcast_replace_to(- trade_republic_item.family,- target: "trade_republic_item_#{trade_republic_item.id}",- partial: "trade_republic_items/trade_republic_item",- locals: { trade_republic_item: trade_republic_item }- )-trade_republic_item.family.broadcast_sync_completeendenddiff --git a/app/models/trading212_item/sync_complete_event.rb b/app/models/trading212_item/sync_complete_event.rbindex 6221997084..20929668e9 100644--- a/app/models/trading212_item/sync_complete_event.rb+++ b/app/models/trading212_item/sync_complete_event.rb@@ -10,13 +10,6 @@ class Trading212Item::SyncCompleteEventaccount.broadcast_sync_completeend- trading212_item.broadcast_replace_to(- trading212_item.family,- target: "trading212_item_#{trading212_item.id}",- partial: "trading212_items/trading212_item",- locals: { trading212_item: trading212_item }- )-trading212_item.family.broadcast_sync_completeendenddiff --git a/app/models/up_item/sync_complete_event.rb b/app/models/up_item/sync_complete_event.rbindex 5c7d4e8d62..a515d69b57 100644--- a/app/models/up_item/sync_complete_event.rb+++ b/app/models/up_item/sync_complete_event.rb@@ -10,13 +10,6 @@ class UpItem::SyncCompleteEventdef broadcastup_item.accounts.each(&:broadcast_sync_complete)- up_item.broadcast_replace_to(- up_item.family,- target: "up_item_#{up_item.id}",- partial: "up_items/up_item",- locals: { up_item: up_item }- )-up_item.family.broadcast_sync_completeendenddiff --git a/app/models/wise_item/sync_complete_event.rb b/app/models/wise_item/sync_complete_event.rbindex 49d24fa437..6b9251ed2e 100644--- a/app/models/wise_item/sync_complete_event.rb+++ b/app/models/wise_item/sync_complete_event.rb@@ -12,13 +12,6 @@ class WiseItem::SyncCompleteEventaccount.broadcast_sync_completeend- wise_item.broadcast_replace_to(- wise_item.family,- target: dom_id(wise_item),- partial: "wise_items/wise_item",- locals: { wise_item: wise_item }- )-wise_item.family.broadcast_sync_completeenddiff --git a/lib/generators/provider/family/templates/activities_fetch_job.rb.tt b/lib/generators/provider/family/templates/activities_fetch_job.rb.ttindex 163263400f..d7d57fb79e 100644--- a/lib/generators/provider/family/templates/activities_fetch_job.rb.tt+++ b/lib/generators/provider/family/templates/activities_fetch_job.rb.tt@@ -117,11 +117,9 @@ class <%= class_name %>ActivitiesFetchJob < ApplicationJobdef broadcast_updates@<%= file_name %>_account.current_account&.broadcast_sync_complete- @<%= file_name %>_account.<%= file_name %>_item&.broadcast_replace_to(- @<%= file_name %>_account.<%= file_name %>_item.family,- target: "<%= file_name %>_item_#{@<%= file_name %>_account.<%= file_name %>_item.id}",- partial: "<%= file_name %>_items/<%= file_name %>_item"- )+ # Not the rendered card, which lists every account on the connection and+ # has no viewer to filter for here (#3630); the toast re-fetches per viewer.+ @<%= file_name %>_account.<%= file_name %>_item&.family&.broadcast_sync_completerescue => eRails.logger.warn("<%= class_name %>ActivitiesFetchJob - Broadcast failed: #{e.message}")enddiff --git a/test/models/ibkr_item/sync_complete_event_test.rb b/test/models/ibkr_item/sync_complete_event_test.rbindex 5fe628434f..73b69fe5ec 100644--- a/test/models/ibkr_item/sync_complete_event_test.rb+++ b/test/models/ibkr_item/sync_complete_event_test.rb@@ -3,19 +3,16 @@ require "test_helper"class IbkrItem::SyncCompleteEventTest < ActiveSupport::TestCasefixtures :families, :ibkr_items- test "broadcast refreshes linked accounts, provider item, and family stream" do+ # The card itself is not re-rendered: it lists every account on the+ # connection and a broadcast has no viewer to filter for (#3630).+ test "broadcast refreshes linked accounts and the family stream, not the card" doibkr_item = ibkr_items(:configured_item)family = ibkr_item.familyaccount = mock("account")ibkr_item.stubs(:accounts).returns([ account ])account.expects(:broadcast_sync_complete).once- ibkr_item.expects(:broadcast_replace_to).with(- family,- target: "ibkr_item_#{ibkr_item.id}",- partial: "ibkr_items/ibkr_item",- locals: { ibkr_item: ibkr_item }- ).once+ ibkr_item.expects(:broadcast_replace_to).neverfamily.expects(:broadcast_sync_complete).onceIbkrItem::SyncCompleteEvent.new(ibkr_item).broadcastdiff --git a/test/models/kraken_item/sync_complete_event_test.rb b/test/models/kraken_item/sync_complete_event_test.rbnew file mode 100644index 0000000000..99772f4250--- /dev/null+++ b/test/models/kraken_item/sync_complete_event_test.rb@@ -0,0 +1,21 @@+require "test_helper"+require "turbo/broadcastable/test_helper"++class KrakenItem::SyncCompleteEventTest < ActiveSupport::TestCase+ include Turbo::Broadcastable::TestHelper++ # #3630. Kraken's event never sent the family toast; it relied on replacing+ # the card. With the card replace gone it must send the toast instead, or a+ # finished sync would leave the page stale.+ test "a sync completion sends the family toast instead of the rendered card" do+ item = kraken_items(:one)++ streams = capture_turbo_stream_broadcasts(item.family) do+ KrakenItem::SyncCompleteEvent.new(item).broadcast+ end++ targets = streams.map { |stream| stream["target"] }+ assert_not_includes targets, ActionView::RecordIdentifier.dom_id(item)+ assert_includes targets, "sync-toast"+ end+enddiff --git a/test/models/onchain_wallet_item/sync_complete_event_test.rb b/test/models/onchain_wallet_item/sync_complete_event_test.rbnew file mode 100644index 0000000000..7cccd56062--- /dev/null+++ b/test/models/onchain_wallet_item/sync_complete_event_test.rb@@ -0,0 +1,34 @@+# frozen_string_literal: true++require "test_helper"+require "turbo/broadcastable/test_helper"++class OnchainWalletItem::SyncCompleteEventTest < ActiveSupport::TestCase+ include OnchainTestHelper+ include Turbo::Broadcastable::TestHelper++ setup do+ register_fake_chain!+ @item = create_onchain_wallet_item(family: families(:dylan_family))+ @onchain_account = create_onchain_wallet_account(item: @item, asset: fake_native_asset(quantity: 0))+ link_onchain_wallet_account!(@onchain_account)+ end++ teardown do+ unregister_fake_chain!+ end++ # #3630. The wallet row names every address on the connection, and every+ # family member subscribes to the family stream, including members the+ # wallet's accounts are not shared with.+ test "a sync completion sends the family toast instead of the rendered wallet row" do+ streams = capture_turbo_stream_broadcasts(@item.family) do+ OnchainWalletItem::SyncCompleteEvent.new(@item).broadcast+ end++ targets = streams.map { |stream| stream["target"] }+ assert_not_includes targets, ActionView::RecordIdentifier.dom_id(@item)+ assert_includes targets, "sync-toast"+ streams.each { |stream| assert_not_includes stream.to_html, @onchain_account.truncated_address }+ end+enddiff --git a/test/models/plaid_item/sync_complete_event_test.rb b/test/models/plaid_item/sync_complete_event_test.rbnew file mode 100644index 0000000000..0807600896--- /dev/null+++ b/test/models/plaid_item/sync_complete_event_test.rb@@ -0,0 +1,22 @@+require "test_helper"+require "turbo/broadcastable/test_helper"++class PlaidItem::SyncCompleteEventTest < ActiveSupport::TestCase+ include Turbo::Broadcastable::TestHelper++ # #3630. The card partial renders every account on the connection, and a sync+ # broadcast has no viewer to filter for. Replacing the card on the family+ # stream would swap a member's filtered card for the full one, so the card+ # is left to the family's sync toast, which re-fetches the page per viewer.+ test "a sync completion does not broadcast the rendered card" do+ item = plaid_items(:one)++ streams = capture_turbo_stream_broadcasts(item.family) do+ PlaidItem::SyncCompleteEvent.new(item).broadcast+ end++ targets = streams.map { |stream| stream["target"] }+ assert_not_includes targets, ActionView::RecordIdentifier.dom_id(item)+ assert_includes targets, "sync-toast"+ end+enddiff --git a/test/models/provider_item_sync_complete_events_test.rb b/test/models/provider_item_sync_complete_events_test.rbnew file mode 100644index 0000000000..4825c637f4--- /dev/null+++ b/test/models/provider_item_sync_complete_events_test.rb@@ -0,0 +1,86 @@+require "test_helper"+require "turbo/broadcastable/test_helper"++# #3630. A provider card lists every account on its connection, and a+# broadcast on the family stream is rendered with no viewer and reaches+# every member. No provider's sync completion may send it; the family sync+# toast makes each browser re-fetch its own, filtered page instead.+class ProviderItemSyncCompleteEventsTest < ActiveSupport::TestCase+ include Turbo::Broadcastable::TestHelper++ PROVIDERS = %w[+ binance_item coinspot_item fio_item ibkr_item indexa_capital_item kraken_item+ lunchflow_item mercury_item monobank_item plaid_item redbark_item+ snaptrade_item trade_republic_item trading212_item wise_item+ ].freeze++ PROVIDERS.each do |provider|+ test "a #{provider} sync completion sends the toast, not the card" do+ item = provider.camelize.constantize.first!+ Current.reset++ streams = capture_turbo_stream_broadcasts(item.family) do+ "#{provider.camelize}::SyncCompleteEvent".constantize.new(item).broadcast+ end+ targets = streams.map { |stream| stream["target"] }++ assert_not_includes targets, ActionView::RecordIdentifier.dom_id(item)+ assert_includes targets, "sync-toast"+ end+ end++ # simplefin_items.yml is empty; SimpleFIN tests build their own item.+ test "a simplefin_item sync completion sends the toast, not the card" do+ item = families(:dylan_family).simplefin_items.create!(name: "SimpleFIN Connection", access_url: "https://example.com/access")+ Current.reset++ streams = capture_turbo_stream_broadcasts(item.family) do+ SimplefinItem::SyncCompleteEvent.new(item).broadcast+ end+ targets = streams.map { |stream| stream["target"] }++ assert_not_includes targets, ActionView::RecordIdentifier.dom_id(item)+ assert_includes targets, "sync-toast"+ end++ # Providers without fixtures, built with only what their validations need.+ {+ "akahu_item" => { app_token: "app", user_token: "user" },+ "coinbase_item" => { api_key: "key", api_secret: "secret" },+ "coinstats_item" => { api_key: "key" },+ "sophtron_item" => { user_id: "user", access_key: "key" },+ "up_item" => { access_token: "token" }+ }.each do |provider, attributes|+ test "a #{provider} sync completion sends the toast, not the card" do+ item = families(:dylan_family).public_send(provider.pluralize).create!(name: "Connection", **attributes)+ Current.reset++ streams = capture_turbo_stream_broadcasts(item.family) do+ "#{provider.camelize}::SyncCompleteEvent".constantize.new(item).broadcast+ end+ targets = streams.map { |stream| stream["target"] }++ assert_not_includes targets, ActionView::RecordIdentifier.dom_id(item)+ assert_includes targets, "sync-toast"+ end+ end++ # The two activity jobs used to send the card themselves once the delayed+ # activities arrived.+ { QuestradeActivitiesFetchJob => [ :questrade_accounts, :one, :questrade_item ],+ IndexaCapitalActivitiesFetchJob => [ :indexa_capital_accounts, :mutual_fund, :indexa_capital_item ] }.each do |job_class, (fixture, name, item_method)|+ test "#{job_class.name} sends the toast, not the card" do+ provider_account = send(fixture, name)+ item = provider_account.public_send(item_method)+ job = job_class.new+ job.instance_variable_set(:"@#{fixture.to_s.singularize}", provider_account)+ Current.reset++ streams = capture_turbo_stream_broadcasts(item.family) { job.send(:broadcast_updates) }+ targets = streams.map { |stream| stream["target"] }++ assert_not_includes targets, ActionView::RecordIdentifier.dom_id(item)+ assert_includes targets, "sync-toast"+ end+ end+end