fix: Resolve infinite sync loop on SnapTrade setup accounts page (#1256)

* Fix infinite sync loop on SnapTrade setup accounts page

* Address PR feedback: behavior assertions & stale sync recovery

- Uses `latest_sync.completed?` so we don't drop dropped/failed syncs
- Replaces `assigns` checks with `assert_select` DOM checks
- Adds required IDs/classes to the html template for assertions
This commit is contained in:
Anas Limouri
2026-03-23 14:22:37 +01:00
committed by GitHub
parent 02a5f5d0da
commit 998ea6f7c5
3 changed files with 70 additions and 4 deletions

View File

@@ -149,8 +149,12 @@ class SnaptradeItemsController < ApplicationController
no_accounts = @unlinked_accounts.blank? && @linked_accounts.blank?
# If no accounts and not syncing, trigger a sync
if no_accounts && !@snaptrade_item.syncing?
# We trigger an initial or recovery sync if there are no accounts, we aren't currently syncing,
# and the last attempt didn't successfully complete. (If it completed and found 0 accounts, we stop here to avoid an infinite loop.)
latest_sync = @snaptrade_item.syncs.ordered.first
should_sync = latest_sync.nil? || !latest_sync.completed?
if no_accounts && !@snaptrade_item.syncing? && should_sync
@snaptrade_item.sync_later
end