The personal finance app for everyone (by everyone)
Ruby
Fix disabled rules executing during automatic sync (#552)
Copilotb6d67b5348ff
diff --git a/app/models/family/syncer.rb b/app/models/family/syncer.rbindex a16c8d6e1f..8621025090 100644--- a/app/models/family/syncer.rb+++ b/app/models/family/syncer.rb@@ -10,7 +10,7 @@ class Family::Syncerfamily.sync_trial_status!Rails.logger.info("Applying rules for family #{family.id}")- family.rules.each do |rule|+ family.rules.where(active: true).each do |rule|rule.apply_laterenddiff --git a/test/models/family/syncer_test.rb b/test/models/family/syncer_test.rbindex 7fe01a7eb6..026d0348f1 100644--- a/test/models/family/syncer_test.rb+++ b/test/models/family/syncer_test.rb@@ -27,4 +27,40 @@ class Family::SyncerTest < ActiveSupport::TestCaseassert_equal "completed", family_sync.reload.statusend++ test "only applies active rules during sync" do+ family_sync = syncs(:family)++ # Create an active rule+ active_rule = @family.rules.create!(+ resource_type: "transaction",+ active: true,+ actions: [ Rule::Action.new(action_type: "exclude_transaction") ]+ )++ # Create a disabled rule+ disabled_rule = @family.rules.create!(+ resource_type: "transaction",+ active: false,+ actions: [ Rule::Action.new(action_type: "exclude_transaction") ]+ )++ syncer = Family::Syncer.new(@family)++ # Stub the relation to return our specific instances so expectations work+ @family.rules.stubs(:where).with(active: true).returns([ active_rule ])++ # Expect apply_later to be called only for the active rule+ active_rule.expects(:apply_later).once+ disabled_rule.expects(:apply_later).never++ # Mock the account and plaid item syncs to avoid side effects+ Account.any_instance.stubs(:sync_later)+ PlaidItem.any_instance.stubs(:sync_later)+ SimplefinItem.any_instance.stubs(:sync_later)+ LunchflowItem.any_instance.stubs(:sync_later)+ EnableBankingItem.any_instance.stubs(:sync_later)++ syncer.perform_sync(family_sync)+ endend