Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

fix(i18n): label the subtype select on account forms (#4981)

Stephan Wentz6f56b0e510ba
diff --git a/app/views/depositories/_form.html.erb b/app/views/depositories/_form.html.erb
index 41a807fcf3..eb92594fec 100644
--- a/app/views/depositories/_form.html.erb
+++ b/app/views/depositories/_form.html.erb
@@ -3,5 +3,5 @@
<%= render "accounts/form", account: account, url: url do |form| %>
<%= form.select :subtype,
Depository.subtype_options_for_select,
- { label: true, prompt: t("depositories.form.subtype_prompt"), include_blank: t("depositories.form.none") } %>
+ { label: Depository.human_attribute_name(:subtype), prompt: t("depositories.form.subtype_prompt"), include_blank: t("depositories.form.none") } %>
<% end %>
diff --git a/config/locales/models/account/de.yml b/config/locales/models/account/de.yml
index 74fa10bb03..3d86db79e1 100644
--- a/config/locales/models/account/de.yml
+++ b/config/locales/models/account/de.yml
@@ -9,6 +9,12 @@ de:
family_id: "%{moniker}"
name: Name
subtype: Untertyp
+ depository:
+ subtype: Kontotyp
+ investment:
+ subtype: Investmenttyp
+ loan:
+ subtype: Kreditart
models:
account: Konto
account/credit: Kreditkarte
diff --git a/config/locales/models/account/en.yml b/config/locales/models/account/en.yml
index 9c09be4b2e..7a6db6d23d 100644
--- a/config/locales/models/account/en.yml
+++ b/config/locales/models/account/en.yml
@@ -26,6 +26,12 @@ en:
logo: Logo
name: Name
subtype: Subtype
+ depository:
+ subtype: Account type
+ investment:
+ subtype: Investment type
+ loan:
+ subtype: Loan type
errors:
models:
account:
diff --git a/test/controllers/depositories_controller_test.rb b/test/controllers/depositories_controller_test.rb
index 0923c63d3d..5b960bcfd4 100644
--- a/test/controllers/depositories_controller_test.rb
+++ b/test/controllers/depositories_controller_test.rb
@@ -9,6 +9,15 @@ class DepositoriesControllerTest < ActionDispatch::IntegrationTest
@account = accounts(:depository)
end
+ # The select sits on the account form, not inside `fields_for :accountable`,
+ # so `label: true` would read Account's attribute name. The form passes the
+ # Depository one instead.
+ test "the account type select is labelled from the locale" do
+ get new_depository_url
+ assert_response :success
+ assert_select "label[for=account_subtype]", text: "Account type"
+ end
+
# The provider link's visibility and the controller's gate are two
# expressions of one rule, and they disagreed. ConnectorAuthorizable requires
# `member_connectable? && Current.user&.member?`; the selector asked only
diff --git a/test/controllers/investments_controller_test.rb b/test/controllers/investments_controller_test.rb
index 63ab9b9189..16c4ef6edd 100644
--- a/test/controllers/investments_controller_test.rb
+++ b/test/controllers/investments_controller_test.rb
@@ -8,6 +8,12 @@ class InvestmentsControllerTest < ActionDispatch::IntegrationTest
@account = accounts(:investment)
end
+ test "the investment type select is labelled from the locale" do
+ get new_investment_url
+ assert_response :success
+ assert_select "label[for=account_accountable_attributes_subtype]", text: "Investment type"
+ end
+
test "changing the method starts one sync of the account" do
assert @account.cost_basis_average?
Account.any_instance.expects(:sync_later).once
diff --git a/test/controllers/loans_controller_test.rb b/test/controllers/loans_controller_test.rb
index afe33675ee..caf2337d25 100644
--- a/test/controllers/loans_controller_test.rb
+++ b/test/controllers/loans_controller_test.rb
@@ -117,6 +117,15 @@ class LoansControllerTest < ActionDispatch::IntegrationTest
assert_equal "level_term", loan.insurance_rate_type
end
+ # The select passes `label: true`, so its text comes from the Loan model's
+ # attribute name. Without a translation Rails humanizes it to "Subtype" in
+ # every locale.
+ test "the loan type select is labelled from the locale" do
+ get new_loan_url
+ assert_response :success
+ assert_select "label[for=account_accountable_attributes_subtype]", text: "Loan type"
+ end
+
# The type select's blank option is the form's "None": no type recorded, read
# as decreasing. It submits an empty string, which must clear the type rather
# than fail validation (and the column's check constraint, which admits NULL
diff --git a/test/i18n_test.rb b/test/i18n_test.rb
index 3f1f557fbb..76a6706e48 100644
--- a/test/i18n_test.rb
+++ b/test/i18n_test.rb
@@ -211,6 +211,17 @@ class I18nTest < ActiveSupport::TestCase
assert_empty extra, "nl placeholders missing from en:\n#{extra.join("\n")}"
end
+ # The depository, investment and loan forms label their subtype select with
+ # the accountable's attribute name. A missing entry humanizes to "Subtype".
+ def test_accountable_subtype_labels_are_translated
+ [ Depository, Investment, Loan ].each do |model|
+ %i[en de].each do |locale|
+ key = "activerecord.attributes.#{model.model_name.i18n_key}.subtype"
+ assert I18n.t(key, locale: locale, fallback: false, default: nil).present?, "#{key} is missing in #{locale}"
+ end
+ end
+ end
+
def test_trade_republic_activity_labels_exist_for_each_locale
required_labels = %w[
contribution withdrawal interest dividend card_payment cash_withdrawal