Add exclude transaction rule action (#437)

* Initial plan

* Add ExcludeTransaction rule action executor with tests

Co-authored-by: jjmata <187772+jjmata@users.noreply.github.com>

* Copy clarification

---------

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: Juan José Mata <juanjo.mata@gmail.com>
This commit is contained in:
Copilot
2025-12-10 12:37:42 +01:00
committed by GitHub
parent ea35296def
commit 4a772d8067
3 changed files with 67 additions and 1 deletions

View File

@@ -55,6 +55,45 @@ class RuleTest < ActiveSupport::TestCase
assert_equal @groceries_category, transaction_entry2.transaction.category
end
test "exclude transaction rule" do
transaction_entry = create_transaction(date: Date.current, account: @account, merchant: @whole_foods_merchant)
assert_not transaction_entry.excluded, "Transaction should not be excluded initially"
rule = Rule.create!(
family: @family,
resource_type: "transaction",
effective_date: 1.day.ago.to_date,
conditions: [ Rule::Condition.new(condition_type: "transaction_merchant", operator: "=", value: @whole_foods_merchant.id) ],
actions: [ Rule::Action.new(action_type: "exclude_transaction") ]
)
rule.apply
transaction_entry.reload
assert transaction_entry.excluded, "Transaction should be excluded after rule applies"
end
test "exclude transaction rule respects attribute locks" do
transaction_entry = create_transaction(date: Date.current, account: @account, merchant: @whole_foods_merchant)
transaction_entry.lock_attr!(:excluded)
rule = Rule.create!(
family: @family,
resource_type: "transaction",
effective_date: 1.day.ago.to_date,
conditions: [ Rule::Condition.new(condition_type: "transaction_merchant", operator: "=", value: @whole_foods_merchant.id) ],
actions: [ Rule::Action.new(action_type: "exclude_transaction") ]
)
rule.apply
transaction_entry.reload
assert_not transaction_entry.excluded, "Transaction should not be excluded when attribute is locked"
end
# Artificial limitation put in place to prevent users from creating overly complex rules
# Rules should be shallow and wide
test "no nested compound conditions" do