mirror of
https://github.com/we-promise/sure.git
synced 2026-09-05 06:41:08 +00:00
fix(transactions): re-render form when creating a transaction with no account (#2777)
TransactionsController#create looked up the account with accessible_accounts.find(params.dig(:entry, :account_id)). With no account selected the id is blank, find raises RecordNotFound, and StoreLocation's rescue_from turns that into head :not_found — the 404 on /transactions the reporter saw. Switch to find_by(id:) and, when it returns nil, rebuild the entry, run validation, and re-render :new with 422, matching the existing validation-failure branch. This covers a blank, missing, or invalid account_id, so the user gets the form back with errors instead of a dead button. Fixes #2566 Co-authored-by: agentloop <agentloop@localhost>
This commit is contained in:
@@ -35,6 +35,27 @@ class TransactionsControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_enqueued_with(job: SyncJob)
|
||||
end
|
||||
|
||||
test "create without an account re-renders the form instead of raising" do
|
||||
assert_no_difference [ "Entry.count", "Transaction.count" ] do
|
||||
post transactions_url, params: {
|
||||
entry: {
|
||||
account_id: "",
|
||||
name: "New transaction",
|
||||
date: Date.current,
|
||||
currency: "USD",
|
||||
amount: 100,
|
||||
nature: "inflow",
|
||||
entryable_type: "Transaction",
|
||||
entryable_attributes: {
|
||||
category_id: Category.first.id
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
assert_response :unprocessable_entity
|
||||
end
|
||||
|
||||
test "updates with transaction details" do
|
||||
assert_no_difference [ "Entry.count", "Transaction.count" ] do
|
||||
patch transaction_url(@entry), params: {
|
||||
|
||||
Reference in New Issue
Block a user