mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-10 07:55:21 +02:00
Simplify reference logic, add a small test
This commit is contained in:
parent
7533179350
commit
75c3adcec0
4 changed files with 18 additions and 15 deletions
|
@ -157,15 +157,11 @@ class Account < ApplicationRecord
|
|||
|
||||
# Get short version of the subtype label
|
||||
def short_subtype_label
|
||||
return nil unless subtype && accountable_type
|
||||
accountable_class = accountable_type.constantize
|
||||
accountable_class.short_subtype_label_for(subtype) || accountable_class.display_name
|
||||
end
|
||||
|
||||
# Get long version of the subtype label
|
||||
def long_subtype_label
|
||||
return nil unless subtype && accountable_type
|
||||
accountable_class = accountable_type.constantize
|
||||
accountable_class.long_subtype_label_for(subtype) || accountable_class.display_name
|
||||
end
|
||||
|
||||
|
|
|
@ -60,16 +60,6 @@ class BalanceSheet
|
|||
classification_total.zero? ? 0 : account.converted_balance / classification_total.to_d * 100
|
||||
end
|
||||
|
||||
# Define our subtype labeling logic with short format (for sidebar)
|
||||
account.define_singleton_method(:short_subtype_label) do
|
||||
accountable.short_subtype_label_for(account.subtype) || accountable.display_name
|
||||
end
|
||||
|
||||
# Define long label method (for other views that might need it)
|
||||
account.define_singleton_method(:long_subtype_label) do
|
||||
accountable.long_subtype_label_for(account.subtype) || accountable.display_name
|
||||
end
|
||||
|
||||
account
|
||||
end.sort_by(&:weight).reverse
|
||||
)
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
</p>
|
||||
<% else %>
|
||||
<%= link_to account.name, account, class: [(account.is_active ? "text-primary" : "text-subdued"), "text-sm font-medium hover:underline"], data: { turbo_frame: "_top" } %>
|
||||
<% if account.respond_to?(:long_subtype_label) && account.long_subtype_label %>
|
||||
<% if account.long_subtype_label %>
|
||||
<p class="text-sm text-secondary truncate"><%= account.long_subtype_label %></p>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
|
|
@ -13,4 +13,21 @@ class AccountTest < ActiveSupport::TestCase
|
|||
@account.destroy
|
||||
end
|
||||
end
|
||||
|
||||
test "gets short/long subtype label" do
|
||||
account = @family.accounts.create!(
|
||||
name: "Test Investment",
|
||||
balance: 1000,
|
||||
currency: "USD",
|
||||
accountable: Investment.new(subtype: "hsa")
|
||||
)
|
||||
|
||||
assert_equal "HSA", account.short_subtype_label
|
||||
assert_equal "Health Savings Account", account.long_subtype_label
|
||||
|
||||
# Test with nil subtype
|
||||
account.update!(subtype: nil)
|
||||
assert_equal "Investments", account.short_subtype_label
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue