From cd41e61caac6420b3d27d161bf2d421aae581ef5 Mon Sep 17 00:00:00 2001 From: Zach Gollwitzer Date: Tue, 17 Jun 2025 14:37:27 -0400 Subject: [PATCH] Remove stale methods --- app/models/transfer.rb | 42 ------------------------------------ test/models/transfer_test.rb | 30 -------------------------- 2 files changed, 72 deletions(-) diff --git a/app/models/transfer.rb b/app/models/transfer.rb index 8fd2937f..7b0ab3cd 100644 --- a/app/models/transfer.rb +++ b/app/models/transfer.rb @@ -12,48 +12,6 @@ class Transfer < ApplicationRecord validate :transfer_within_date_range validate :transfer_has_same_family - class << self - def from_accounts(from_account:, to_account:, date:, amount:) - # Attempt to convert the amount to the to_account's currency. - # If the conversion fails, use the original amount. - converted_amount = begin - Money.new(amount.abs, from_account.currency).exchange_to(to_account.currency) - rescue Money::ConversionError - Money.new(amount.abs, from_account.currency) - end - - outflow_kind = if to_account&.accountable_type == "Loan" - "loan_payment" - elsif to_account&.liability? - "payment" - else - "transfer" - end - - new( - inflow_transaction: Transaction.new( - kind: "transfer", - entry: to_account.entries.build( - amount: converted_amount.amount.abs * -1, - currency: converted_amount.currency.iso_code, - date: date, - name: "Transfer from #{from_account.name}", - ) - ), - outflow_transaction: Transaction.new( - kind: outflow_kind, - entry: from_account.entries.build( - amount: amount.abs, - currency: from_account.currency, - date: date, - name: "Transfer to #{to_account.name}", - ) - ), - status: "confirmed" - ) - end - end - def reject! Transfer.transaction do RejectedTransfer.find_or_create_by!(inflow_transaction_id: inflow_transaction_id, outflow_transaction_id: outflow_transaction_id) diff --git a/test/models/transfer_test.rb b/test/models/transfer_test.rb index 36dc56d4..33163816 100644 --- a/test/models/transfer_test.rb +++ b/test/models/transfer_test.rb @@ -93,36 +93,6 @@ class TransferTest < ActiveSupport::TestCase assert_equal "Must be from same family", transfer.errors.full_messages.first end - test "from_accounts converts amounts to the to_account's currency" do - accounts(:depository).update!(currency: "EUR") - - eur_account = accounts(:depository).reload - usd_account = accounts(:credit_card) - - ExchangeRate.create!( - from_currency: "EUR", - to_currency: "USD", - rate: 1.1, - date: Date.current, - ) - - transfer = Transfer.from_accounts( - from_account: eur_account, - to_account: usd_account, - date: Date.current, - amount: 500, - ) - - assert_equal 500, transfer.outflow_transaction.entry.amount - assert_equal "EUR", transfer.outflow_transaction.entry.currency - assert_equal -550, transfer.inflow_transaction.entry.amount - assert_equal "USD", transfer.inflow_transaction.entry.currency - - assert_difference -> { Transfer.count } => 1 do - transfer.save! - end - end - test "transaction can only belong to one transfer" do outflow_entry = create_transaction(date: Date.current, account: accounts(:depository), amount: 500) inflow_entry1 = create_transaction(date: Date.current, account: accounts(:credit_card), amount: -500)