mirror of
https://github.com/we-promise/sure.git
synced 2026-04-17 02:54:10 +00:00
Fix disabled rules executing during automatic sync (#552)
* Initial plan * Fix: Only apply active rules during sync Co-authored-by: jjmata <187772+jjmata@users.noreply.github.com> * FIX test --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: jjmata <187772+jjmata@users.noreply.github.com> Co-authored-by: sokie <sokysrm@gmail.com>
This commit is contained in:
@@ -10,7 +10,7 @@ class Family::Syncer
|
||||
family.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_later
|
||||
end
|
||||
|
||||
|
||||
@@ -27,4 +27,40 @@ class Family::SyncerTest < ActiveSupport::TestCase
|
||||
|
||||
assert_equal "completed", family_sync.reload.status
|
||||
end
|
||||
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user