Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Derive the reset's provider connections from the family sync (#4927)

Molly6f7c8778adb2
diff --git a/app/models/family/financial_data_reset.rb b/app/models/family/financial_data_reset.rb
index 9a811734bc..5de104ad61 100644
--- a/app/models/family/financial_data_reset.rb
+++ b/app/models/family/financial_data_reset.rb
@@ -40,49 +40,14 @@ class Family::FinancialDataReset
active_storage_attachments
].freeze
STATUS_COUNT_KEYS = (COUNT_KEYS - %i[syncs]) + %i[plaid_items]
- # sorted
- PROVIDER_ITEM_ASSOCIATIONS = %i[
- akahu_items
- binance_items
- brex_items
- coinbase_items
- coinspot_items
- coinstats_items
- enable_banking_items
- financekit_items
- fio_items
- ibkr_items
- indexa_capital_items
- kraken_items
- lunchflow_items
- mercury_items
- monobank_items
- onchain_wallet_items
- plaid_items
- questrade_items
- redbark_items
- sharesight_items
- simplefin_items
- snaptrade_items
- sophtron_items
- trade_republic_items
- trading212_items
- truelayer_items
- up_items
- wise_items
- ].freeze
Result = Struct.new(:user, :family, :dry_run, :before_counts, :deleted_counts, :after_counts, keyword_init: true)
class << self
+ # The same associations the family sync runs, so a provider is reset as
+ # soon as it is synced.
def provider_item_associations
- PROVIDER_ITEM_ASSOCIATIONS.select do |association_name|
- association = Family.reflect_on_association(association_name)
-
- association&.klass&.included_modules&.include?(Syncable)
- rescue NameError
- false
- end
+ Family::Syncer.syncable_item_associations
end
end
diff --git a/app/models/family/syncer.rb b/app/models/family/syncer.rb
index 128c92c786..6d98712604 100644
--- a/app/models/family/syncer.rb
+++ b/app/models/family/syncer.rb
@@ -30,7 +30,8 @@ class Family::Syncer
# Every `*_items` association whose model is Syncable, found by reflection
# so a new integration takes part in the nightly family sync (and may carry
# a SyncSchedule) as soon as it includes Syncable and exposes a `syncable`
- # scope.
+ # scope. This list also drives the destructive Family::FinancialDataReset, so
+ # an association added here is wiped by a reset as well.
def self.syncable_item_associations
Family.reflect_on_all_associations(:has_many).filter_map do |association|
next unless association.name.to_s.end_with?("_items")
diff --git a/test/lib/rubocop/cop/sure/sorted_list_test.rb b/test/lib/rubocop/cop/sure/sorted_list_test.rb
index d4f1add50d..c8207cec4e 100644
--- a/test/lib/rubocop/cop/sure/sorted_list_test.rb
+++ b/test/lib/rubocop/cop/sure/sorted_list_test.rb
@@ -42,8 +42,7 @@ class RuboCop::Cop::Sure::SortedListTest < ActiveSupport::TestCase
end
test "checks each list in the repository it marks" do
- marked = %w[app/models/data_enrichment.rb app/models/provider_merchant.rb app/models/transaction.rb
- app/models/family/financial_data_reset.rb]
+ marked = %w[app/models/data_enrichment.rb app/models/provider_merchant.rb app/models/transaction.rb]
marked.each do |path|
source = Rails.root.join(path).read
diff --git a/test/models/family/financial_data_reset_test.rb b/test/models/family/financial_data_reset_test.rb
index e0031bdbd0..c59f9e0cbe 100644
--- a/test/models/family/financial_data_reset_test.rb
+++ b/test/models/family/financial_data_reset_test.rb
@@ -24,11 +24,11 @@ class Family::FinancialDataResetTest < ActiveSupport::TestCase
assert User.exists?(@user.id)
end
- test "provider item associations are limited to explicit syncable family associations" do
+ test "provider item associations are the syncable family associations" do
associations = Family::FinancialDataReset.provider_item_associations
assert_not_empty associations
- assert_equal associations, Family::FinancialDataReset::PROVIDER_ITEM_ASSOCIATIONS
+ assert_equal Family::Syncer.syncable_item_associations, associations
assert associations.all? { |name| name.to_s.end_with?("_items") }
associations.each do |name|
@@ -40,12 +40,6 @@ class Family::FinancialDataResetTest < ActiveSupport::TestCase
end
end
- test "provider item associations cover every syncable family association" do
- missing = Family::Syncer.syncable_item_associations - Family::FinancialDataReset.provider_item_associations
-
- assert_empty missing, "reset leaves provider connections behind: #{missing.join(', ')}"
- end
-
test "sync counts use the family sync scope without double counting" do
account = @family.accounts.first
provider_item = @family.plaid_items.first