mirror of
https://github.com/we-promise/sure.git
synced 2026-04-19 03:54:08 +00:00
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:
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user