Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Keep disabled accounts visible for toggling (#361)

Juan José Mata51d1cea51d25
diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rb
index b70cf6d243..f5bab529d5 100644
--- a/app/controllers/accounts_controller.rb
+++ b/app/controllers/accounts_controller.rb
@@ -4,7 +4,7 @@ class AccountsController < ApplicationController
def index
@manual_accounts = family.accounts
- .visible_manual
+ .listable_manual
.order(:name)
@plaid_items = family.plaid_items.ordered
@simplefin_items = family.simplefin_items.ordered.includes(:syncs)
@@ -18,7 +18,7 @@ class AccountsController < ApplicationController
latest_sync = item.syncs.ordered.first
@simplefin_sync_stats_map[item.id] = (latest_sync&.sync_stats || {})
@simplefin_has_unlinked_map[item.id] = item.family.accounts
- .visible_manual
+ .listable_manual
.exists?
end
diff --git a/app/models/account.rb b/app/models/account.rb
index a53c39451b..d82872f6b9 100644
--- a/app/models/account.rb
+++ b/app/models/account.rb
@@ -32,6 +32,10 @@ class Account < ApplicationRecord
visible.manual
}
+ scope :listable_manual, -> {
+ manual.where.not(status: :pending_deletion)
+ }
+
has_one_attached :logo
delegated_type :accountable, types: Accountable::TYPES, dependent: :destroy
diff --git a/test/controllers/accounts_controller_test.rb b/test/controllers/accounts_controller_test.rb
index f5699b1f3f..4c690ce0b8 100644
--- a/test/controllers/accounts_controller_test.rb
+++ b/test/controllers/accounts_controller_test.rb
@@ -130,6 +130,28 @@ class AccountsControllerTest < ActionDispatch::IntegrationTest
assert_equal "Depository account scheduled for deletion", flash[:notice]
end
+ test "disabling an account keeps it visible on index" do
+ @account.disable!
+
+ get accounts_path
+
+ assert_response :success
+ assert_includes @response.body, @account.name
+ assert_includes @response.body, "account_#{@account.id}_active"
+ end
+
+ test "toggle_active disables and re-enables an account" do
+ patch toggle_active_account_url(@account)
+ assert_redirected_to accounts_path
+ @account.reload
+ assert @account.disabled?
+
+ patch toggle_active_account_url(@account)
+ assert_redirected_to accounts_path
+ @account.reload
+ assert @account.active?
+ end
+
test "select_provider shows available providers" do
get select_provider_account_url(@account)
assert_response :success