mirror of
https://github.com/we-promise/sure.git
synced 2026-04-19 20:14:08 +00:00
Fix tags getting removed after / during bank sync (#634)
* fix: Preserve transaction tags during rule application When rules set tags, they now ADD to existing tags instead of replacing them. This fixes issue #518 where tags were being removed during bank sync. The root cause was that SetTransactionTags called enrich_attribute with just the single tag from the rule, which replaced all existing tags. Now it merges the new tag with existing tags using .uniq to prevent duplicates. This preserves: - User-applied tags that shouldn't be overwritten by rules - Tags from other rules when multiple rules match the same transaction - Tags set during previous syncs * fix: Add nil guard for tag in SetTransactionTags Return early with 0 if the tag is not found, preventing NoMethodError when find_by_id returns nil. This matches the pattern used in SetTransactionMerchant. --------- Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -1219,6 +1219,41 @@ class Account::ProviderImportAdapterTest < ActiveSupport::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
test "preserves transaction tags when re-importing existing transaction" do
|
||||
tag = Tag.create!(name: "Salary", family: @family)
|
||||
|
||||
# Create initial transaction
|
||||
entry = @adapter.import_transaction(
|
||||
external_id: "plaid_tag_test",
|
||||
amount: 1000.00,
|
||||
currency: "USD",
|
||||
date: Date.today,
|
||||
name: "Paycheck",
|
||||
source: "plaid"
|
||||
)
|
||||
|
||||
# Add tag to the transaction (simulating user or rule action)
|
||||
entry.transaction.tags << tag
|
||||
entry.transaction.save!
|
||||
assert_equal [ tag ], entry.transaction.reload.tags
|
||||
|
||||
# Re-import the same transaction with updated data
|
||||
assert_no_difference "@account.entries.count" do
|
||||
updated_entry = @adapter.import_transaction(
|
||||
external_id: "plaid_tag_test",
|
||||
amount: 1000.00,
|
||||
currency: "USD",
|
||||
date: Date.today,
|
||||
name: "Updated Paycheck Name",
|
||||
source: "plaid"
|
||||
)
|
||||
|
||||
assert_equal entry.id, updated_entry.id
|
||||
# Tags should be preserved
|
||||
assert_equal [ tag ], updated_entry.transaction.reload.tags
|
||||
end
|
||||
end
|
||||
|
||||
test "Plaid pending_transaction_id takes priority over amount matching" do
|
||||
# Create TWO pending transactions with same amount
|
||||
pending1 = @adapter.import_transaction(
|
||||
|
||||
Reference in New Issue
Block a user