mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-23 07:09:39 +02:00
Add institution management and account editing controls (#868)
* Add institution management * Allow user to select institution on create or edit * Improve redirect behavior * Final cleanup * i18n normalization
This commit is contained in:
parent
8c1a7af37f
commit
9956a9540e
36 changed files with 456 additions and 68 deletions
|
@ -6,6 +6,15 @@ class AccountsControllerTest < ActionDispatch::IntegrationTest
|
|||
@account = accounts(:checking)
|
||||
end
|
||||
|
||||
test "gets accounts list" do
|
||||
get accounts_url
|
||||
assert_response :success
|
||||
|
||||
@user.family.accounts.each do |account|
|
||||
assert_dom "#" + dom_id(account), count: 1
|
||||
end
|
||||
end
|
||||
|
||||
test "new" do
|
||||
get new_account_path
|
||||
assert_response :ok
|
||||
|
@ -19,7 +28,9 @@ class AccountsControllerTest < ActionDispatch::IntegrationTest
|
|||
test "should update account" do
|
||||
patch account_url(@account), params: {
|
||||
account: {
|
||||
is_active: "0"
|
||||
name: "Updated name",
|
||||
is_active: "0",
|
||||
institution_id: institutions(:chase).id
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -33,7 +44,8 @@ class AccountsControllerTest < ActionDispatch::IntegrationTest
|
|||
account: {
|
||||
accountable_type: "Account::Depository",
|
||||
balance: 200,
|
||||
subtype: "checking"
|
||||
subtype: "checking",
|
||||
institution_id: institutions(:chase).id
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -49,6 +61,7 @@ class AccountsControllerTest < ActionDispatch::IntegrationTest
|
|||
accountable_type: "Account::Depository",
|
||||
balance: 200,
|
||||
subtype: "checking",
|
||||
institution_id: institutions(:chase).id,
|
||||
start_balance: 100,
|
||||
start_date: 10.days.ago
|
||||
}
|
||||
|
|
55
test/controllers/institutions_controller_test.rb
Normal file
55
test/controllers/institutions_controller_test.rb
Normal file
|
@ -0,0 +1,55 @@
|
|||
require "test_helper"
|
||||
|
||||
class InstitutionsControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
sign_in users(:family_admin)
|
||||
@institution = institutions(:chase)
|
||||
end
|
||||
|
||||
test "should get new" do
|
||||
get new_institution_url
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "can create institution" do
|
||||
assert_difference("Institution.count", 1) do
|
||||
post institutions_url, params: {
|
||||
institution: {
|
||||
name: "New institution"
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
assert_redirected_to accounts_url
|
||||
assert_equal "Institution created", flash[:notice]
|
||||
end
|
||||
|
||||
test "should get edit" do
|
||||
get edit_institution_url(@institution)
|
||||
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should update institution" do
|
||||
patch institution_url(@institution), params: {
|
||||
institution: {
|
||||
name: "New Institution Name",
|
||||
logo: file_fixture_upload("square-placeholder.png", "image/png", :binary)
|
||||
}
|
||||
}
|
||||
|
||||
assert_redirected_to accounts_url
|
||||
assert_equal "Institution updated", flash[:notice]
|
||||
end
|
||||
|
||||
test "can destroy institution without destroying accounts" do
|
||||
assert @institution.accounts.count > 0
|
||||
|
||||
assert_difference -> { Institution.count } => -1, -> { Account.count } => 0 do
|
||||
delete institution_url(@institution)
|
||||
end
|
||||
|
||||
assert_redirected_to accounts_url
|
||||
assert_equal "Institution deleted", flash[:notice]
|
||||
end
|
||||
end
|
5
test/fixtures/accounts.yml
vendored
5
test/fixtures/accounts.yml
vendored
|
@ -13,6 +13,7 @@ checking:
|
|||
balance: 5000
|
||||
accountable_type: Account::Depository
|
||||
accountable_id: "123e4567-e89b-12d3-a456-426614174000"
|
||||
institution: chase
|
||||
|
||||
# Account with both transactions and valuations
|
||||
savings_with_valuation_overrides:
|
||||
|
@ -21,6 +22,7 @@ savings_with_valuation_overrides:
|
|||
balance: 20000
|
||||
accountable_type: Account::Depository
|
||||
accountable_id: "123e4567-e89b-12d3-a456-426614174001"
|
||||
institution: chase
|
||||
|
||||
# Liability account
|
||||
credit_card:
|
||||
|
@ -29,6 +31,7 @@ credit_card:
|
|||
balance: 1000
|
||||
accountable_type: Account::Credit
|
||||
accountable_id: "123e4567-e89b-12d3-a456-426614174003"
|
||||
institution: chase
|
||||
|
||||
eur_checking:
|
||||
family: dylan_family
|
||||
|
@ -37,6 +40,7 @@ eur_checking:
|
|||
balance: 12000
|
||||
accountable_type: Account::Depository
|
||||
accountable_id: "123e4567-e89b-12d3-a456-426614174004"
|
||||
institution: revolut
|
||||
|
||||
# Multi-currency account (e.g. Wise, Revolut, etc.)
|
||||
multi_currency:
|
||||
|
@ -46,3 +50,4 @@ multi_currency:
|
|||
balance: 10000
|
||||
accountable_type: Account::Depository
|
||||
accountable_id: "123e4567-e89b-12d3-a456-426614174005"
|
||||
institution: revolut
|
||||
|
|
4
test/fixtures/active_storage/attachments.yml
vendored
Normal file
4
test/fixtures/active_storage/attachments.yml
vendored
Normal file
|
@ -0,0 +1,4 @@
|
|||
chase_logo_attachment:
|
||||
name: logo
|
||||
record: chase (Institution)
|
||||
blob: square_placeholder_blob
|
1
test/fixtures/active_storage/blobs.yml
vendored
Normal file
1
test/fixtures/active_storage/blobs.yml
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
square_placeholder_blob: <%= ActiveStorage::FixtureSet.blob filename: "square-placeholder.png" %>
|
BIN
test/fixtures/files/square-placeholder.png
vendored
Normal file
BIN
test/fixtures/files/square-placeholder.png
vendored
Normal file
Binary file not shown.
After Width: | Height: | Size: 7.4 KiB |
8
test/fixtures/institutions.yml
vendored
Normal file
8
test/fixtures/institutions.yml
vendored
Normal file
|
@ -0,0 +1,8 @@
|
|||
chase:
|
||||
name: Chase
|
||||
family: dylan_family
|
||||
|
||||
revolut:
|
||||
name: Revolut
|
||||
family: dylan_family
|
||||
logo_url: <%= "file://" + Rails.root.join('test/fixtures/files/square-placeholder.png').to_s %>
|
Loading…
Add table
Add a link
Reference in a new issue