1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-19 13:19:39 +02:00

Find account first and build transaction through association (#487)

* Find account first and build transaction through association

* Fix flaky test
This commit is contained in:
Dwight Watson 2024-02-26 22:29:28 +11:00 committed by GitHub
parent 87b97b3c41
commit 971347c761
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 6 deletions

View file

@ -17,12 +17,9 @@ class TransactionsController < ApplicationController
end
def create
@transaction = Transaction.new(transaction_params)
account = Current.family.accounts.find(params[:transaction][:account_id])
raise ActiveRecord::RecordNotFound, "Account not found or not accessible" if account.nil?
@transaction.account = account
@transaction = account.transactions.build(transaction_params)
respond_to do |format|
if @transaction.save

View file

@ -17,11 +17,12 @@ class TransactionsControllerTest < ActionDispatch::IntegrationTest
end
test "should create transaction" do
name = "transaction_name"
assert_difference("Transaction.count") do
post transactions_url, params: { transaction: { account_id: @transaction.account_id, amount: @transaction.amount, currency: @transaction.currency, date: @transaction.date, name: @transaction.name } }
post transactions_url, params: { transaction: { account_id: @transaction.account_id, amount: @transaction.amount, currency: @transaction.currency, date: @transaction.date, name: } }
end
assert_redirected_to transaction_url(Transaction.last)
assert_redirected_to transaction_url(Transaction.find_by(name:))
end
test "should show transaction" do