mirror of
https://github.com/we-promise/sure.git
synced 2026-07-23 18:25:23 +00:00
* Add per-account toggle to disable automatic transaction categorization Adds an `enable_category_matcher` boolean (default: true) to accounts so users can opt out of Plaid's automatic category suggestions on a per-account basis. When disabled, newly synced transactions arrive uncategorized so rules or manual assignment take precedence. - New migration adds `enable_category_matcher` column (default true, null: false) - `PlaidEntry::Processor#matched_category` gates the CategoryMatcher call on the account flag - Toggle rendered in the account edit modal for linked accounts (saves via main form submit) - `AccountableResource#account_params` permits the new field - `AccountsController#toggle_category_matcher` action added for potential API use - i18n strings added for label and hint text - Unit test covers the disabled-matcher path Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Only show category matcher toggle for Plaid-linked accounts Only PlaidEntry::Processor honors enable_category_matcher, but the toggle rendered for every linked account, silently doing nothing for other providers. Adds Account::Linkable#supports_category_matcher? (covering both the legacy plaid_account_id link and AccountProvider rows) and gates the form toggle on it. The SimpleFIN TODO now also points at this helper so the toggle appears once SimpleFIN matching lands. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * Add controller tests for category matcher toggle persistence and rendering Covers the two paths flagged in review as untested: the flag persisting through the shared AccountableResource#update action via account_params (both disable and re-enable), and the edit form rendering the toggle only for accounts where supports_category_matcher? is true. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Signed-off-by: Mike Lloyd <49411532+mike-lloyd03@users.noreply.github.com> Signed-off-by: Juan José Mata <juanjo.mata@gmail.com> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: Juan José Mata <juanjo.mata@gmail.com>
69 lines
2.3 KiB
Ruby
69 lines
2.3 KiB
Ruby
require "test_helper"
|
|
|
|
class DepositoriesControllerTest < ActionDispatch::IntegrationTest
|
|
include AccountableResourceInterfaceTest
|
|
|
|
setup do
|
|
sign_in @user = users(:family_admin)
|
|
@account = accounts(:depository)
|
|
end
|
|
|
|
test "create falls back to the stored return_to when no form param is present" do
|
|
get new_account_path(return_to: transactions_path) # StoreLocation captures it into the session
|
|
|
|
assert_difference -> { Account.count } => 1 do
|
|
post depositories_path, params: {
|
|
account: { name: "Return To Checking", currency: "USD", balance: 100, accountable_type: "Depository" }
|
|
}
|
|
end
|
|
|
|
assert_redirected_to transactions_path
|
|
end
|
|
|
|
test "create prefers the form return_to over the session value" do
|
|
get new_account_path(return_to: transactions_path) # session return_to
|
|
|
|
post depositories_path, params: {
|
|
account: { name: "Form RT Checking", currency: "USD", balance: 100, accountable_type: "Depository", return_to: budgets_path }
|
|
}
|
|
|
|
assert_redirected_to budgets_path
|
|
end
|
|
|
|
test "create ignores an external return_to (open-redirect guard)" do
|
|
post depositories_path, params: {
|
|
account: { name: "Evil RT Checking", currency: "USD", balance: 100, accountable_type: "Depository", return_to: "https://evil.example/phish" }
|
|
}
|
|
|
|
created = Account.order(:created_at).last
|
|
assert_redirected_to account_path(created) # not the external URL
|
|
end
|
|
|
|
test "update persists enable_category_matcher through the shared update action" do
|
|
linked_account = accounts(:connected)
|
|
assert linked_account.enable_category_matcher?
|
|
|
|
patch depository_path(linked_account), params: {
|
|
account: { enable_category_matcher: "0" }
|
|
}
|
|
|
|
refute linked_account.reload.enable_category_matcher?
|
|
|
|
patch depository_path(linked_account), params: {
|
|
account: { enable_category_matcher: "1" }
|
|
}
|
|
|
|
assert linked_account.reload.enable_category_matcher?
|
|
end
|
|
|
|
test "edit form renders category matcher toggle only for accounts that support it" do
|
|
get edit_account_url(accounts(:connected))
|
|
assert_response :success
|
|
assert_select "input[type=checkbox][name='account[enable_category_matcher]']", 1
|
|
|
|
get edit_account_url(accounts(:depository))
|
|
assert_response :success
|
|
assert_select "input[name='account[enable_category_matcher]']", 0
|
|
end
|
|
end
|