mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-25 08:09:38 +02:00
Account namespace updates: part 4 (transfers, singular namespacing) (#896)
* Move Transfer to Account namespace * Fix partial resolution due to namespacing plurality * Make category and tag controllers consistent with namespacing convention * Update stale partial reference
This commit is contained in:
parent
dc3147c101
commit
bddaab0192
50 changed files with 227 additions and 127 deletions
|
@ -1,19 +1,19 @@
|
|||
require "test_helper"
|
||||
|
||||
class TransfersControllerTest < ActionDispatch::IntegrationTest
|
||||
class Account::TransfersControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
sign_in users(:family_admin)
|
||||
end
|
||||
|
||||
test "should get new" do
|
||||
get new_transfer_url
|
||||
get new_account_transfer_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "can create transfers" do
|
||||
assert_difference "Transfer.count", 1 do
|
||||
post transfers_url, params: {
|
||||
transfer: {
|
||||
assert_difference "Account::Transfer.count", 1 do
|
||||
post account_transfers_url, params: {
|
||||
account_transfer: {
|
||||
from_account_id: accounts(:checking).id,
|
||||
to_account_id: accounts(:savings).id,
|
||||
date: Date.current,
|
||||
|
@ -26,8 +26,8 @@ class TransfersControllerTest < ActionDispatch::IntegrationTest
|
|||
end
|
||||
|
||||
test "can destroy transfer" do
|
||||
assert_difference -> { Transfer.count } => -1, -> { Transaction.count } => 0 do
|
||||
delete transfer_url(transfers(:credit_card_payment))
|
||||
assert_difference -> { Account::Transfer.count } => -1, -> { Transaction.count } => 0 do
|
||||
delete account_transfer_url(account_transfers(:credit_card_payment))
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,6 +1,6 @@
|
|||
require "test_helper"
|
||||
|
||||
class Categories::DeletionsControllerTest < ActionDispatch::IntegrationTest
|
||||
class Category::DeletionsControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
sign_in users(:family_admin)
|
||||
@category = categories(:food_and_drink)
|
|
@ -1,6 +1,6 @@
|
|||
require "test_helper"
|
||||
|
||||
class Tags::DeletionsControllerTest < ActionDispatch::IntegrationTest
|
||||
class Tag::DeletionsControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
sign_in @user = users(:family_admin)
|
||||
@user_tags = @user.family.tags
|
2
test/fixtures/accounts.yml
vendored
2
test/fixtures/accounts.yml
vendored
|
@ -22,7 +22,7 @@ checking:
|
|||
|
||||
savings:
|
||||
family: dylan_family
|
||||
name: Savings account with valuation overrides
|
||||
name: Savings account
|
||||
balance: 19700
|
||||
accountable_type: Depository
|
||||
accountable: depository_savings
|
||||
|
|
|
@ -8,14 +8,14 @@ class TransferTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
test "transfer valid if it has inflow and outflow from different accounts for the same amount" do
|
||||
transfer = Transfer.create! transactions: [ @inflow, @outflow ]
|
||||
transfer = Account::Transfer.create! transactions: [ @inflow, @outflow ]
|
||||
|
||||
assert transfer.valid?
|
||||
end
|
||||
|
||||
test "transfer must have 2 transactions" do
|
||||
invalid_transfer_1 = Transfer.new transactions: [ @outflow ]
|
||||
invalid_transfer_2 = Transfer.new transactions: [ @inflow, @outflow, transactions(:savings_four) ]
|
||||
invalid_transfer_1 = Account::Transfer.new transactions: [ @outflow ]
|
||||
invalid_transfer_2 = Account::Transfer.new transactions: [ @inflow, @outflow, transactions(:savings_four) ]
|
||||
|
||||
assert invalid_transfer_1.invalid?
|
||||
assert invalid_transfer_2.invalid?
|
||||
|
@ -27,7 +27,7 @@ class TransferTest < ActiveSupport::TestCase
|
|||
outflow = account.transactions.create! date: Date.current, name: "Outflow", amount: 100
|
||||
|
||||
assert_raise ActiveRecord::RecordInvalid do
|
||||
Transfer.create! transactions: [ inflow, outflow ]
|
||||
Account::Transfer.create! transactions: [ inflow, outflow ]
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -35,7 +35,7 @@ class TransferTest < ActiveSupport::TestCase
|
|||
@inflow.update! marked_as_transfer: false
|
||||
|
||||
assert_raise ActiveRecord::RecordInvalid do
|
||||
Transfer.create! transactions: [ @inflow, @outflow ]
|
||||
Account::Transfer.create! transactions: [ @inflow, @outflow ]
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -43,7 +43,7 @@ class TransferTest < ActiveSupport::TestCase
|
|||
@outflow.update! amount: 105
|
||||
|
||||
assert_raises ActiveRecord::RecordInvalid do
|
||||
Transfer.create! transactions: [ @inflow, @outflow ]
|
||||
Account::Transfer.create! transactions: [ @inflow, @outflow ]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
82
test/system/transfers_test.rb
Normal file
82
test/system/transfers_test.rb
Normal file
|
@ -0,0 +1,82 @@
|
|||
require "application_system_test_case"
|
||||
|
||||
class TransfersTest < ApplicationSystemTestCase
|
||||
setup do
|
||||
sign_in @user = users(:family_admin)
|
||||
visit transactions_url
|
||||
end
|
||||
|
||||
test "can create a transfer" do
|
||||
checking_name = accounts(:checking).name
|
||||
savings_name = accounts(:savings).name
|
||||
transfer_date = Date.current
|
||||
|
||||
click_on "New transaction"
|
||||
|
||||
# Will navigate to different route in same modal
|
||||
click_on "Transfer"
|
||||
assert_text "New transfer"
|
||||
|
||||
fill_in "Description", with: "Transfer txn name"
|
||||
select checking_name, from: "From"
|
||||
select savings_name, from: "To"
|
||||
fill_in "account_transfer[amount]", with: 500
|
||||
fill_in "Date", with: transfer_date
|
||||
click_button "Create transfer"
|
||||
|
||||
within "#date-group-" + transfer_date.to_s do
|
||||
transfer_name = "Transfer from #{checking_name} to #{savings_name}"
|
||||
find("details", text: transfer_name).click
|
||||
assert_text "Transfer txn name", count: 2
|
||||
end
|
||||
end
|
||||
|
||||
test "can match 2 transactions and create a transfer" do
|
||||
transfer_date = Date.current
|
||||
outflow = Transaction.create! name: "Outflow from savings account", date: transfer_date, account: accounts(:savings), amount: 100
|
||||
inflow = Transaction.create! name: "Inflow to checking account", date: transfer_date, account: accounts(:checking), amount: -100
|
||||
|
||||
visit transactions_url
|
||||
|
||||
transaction_checkbox(inflow).check
|
||||
transaction_checkbox(outflow).check
|
||||
|
||||
bulk_transfer_action_button.click
|
||||
|
||||
click_on "Mark as transfers"
|
||||
|
||||
within "#date-group-" + transfer_date.to_s do
|
||||
transfer_name = "Transfer from #{outflow.account.name} to #{inflow.account.name}"
|
||||
find("details", text: transfer_name).click
|
||||
assert_text inflow.name
|
||||
assert_text outflow.name
|
||||
end
|
||||
end
|
||||
|
||||
test "can mark a single transaction as a transfer" do
|
||||
txn = @user.family.transactions.ordered.first
|
||||
|
||||
within "#" + dom_id(txn) do
|
||||
assert_text "Uncategorized"
|
||||
end
|
||||
|
||||
transaction_checkbox(txn).check
|
||||
|
||||
bulk_transfer_action_button.click
|
||||
click_on "Mark as transfers"
|
||||
|
||||
within "#" + dom_id(txn) do
|
||||
assert_no_text "Uncategorized"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def transaction_checkbox(transaction)
|
||||
find("#" + dom_id(transaction, "selection"))
|
||||
end
|
||||
|
||||
def bulk_transfer_action_button
|
||||
find("#bulk-transfer-btn")
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue