Skip to content

armgit / sure

Public Imported from GitHub
0

The personal finance app for everyone (by everyone)

Ruby

Label the cost basis overwrite confirmation button via t() (#4416)

GFR6d7855a857f5
diff --git a/app/views/holdings/_cost_basis_form.html.erb b/app/views/holdings/_cost_basis_form.html.erb
index f6e646fab0..08a6c19c2e 100644
--- a/app/views/holdings/_cost_basis_form.html.erb
+++ b/app/views/holdings/_cost_basis_form.html.erb
@@ -19,10 +19,10 @@
# the holdings-list frame and the drawer for the redirect to the account.
form_data = { turbo_frame: "_top" }
if holding.avg_cost
- form_data[:turbo_confirm] = {
+ form_data[:turbo_confirm] = CustomConfirm.new(
title: t("holdings.cost_basis_cell.overwrite_confirm_title"),
body: t("holdings.cost_basis_cell.overwrite_confirm_body", current: format_money(holding.avg_cost))
- }
+ ).to_data_attribute
end
%>
diff --git a/test/controllers/holdings_controller_test.rb b/test/controllers/holdings_controller_test.rb
index b658489a26..9faa65fa29 100644
--- a/test/controllers/holdings_controller_test.rb
+++ b/test/controllers/holdings_controller_test.rb
@@ -163,6 +163,18 @@ class HoldingsControllerTest < ActionDispatch::IntegrationTest
assert_select "form[data-controller=cost-basis-form][data-turbo=false]", count: 0
end
+ test "cost basis overwrite confirmation labels its button in the user's language" do
+ users(:family_admin).update!(locale: "de")
+ @holding.update!(qty: 10, cost_basis: 12.5, cost_basis_locked: true)
+
+ get holding_path(@holding)
+
+ form = css_select("form[data-controller=cost-basis-form]").first
+ confirmation = JSON.parse(form["data-turbo-confirm"])
+ assert_equal I18n.t("holdings.cost_basis_cell.overwrite_confirm_title", locale: :de), confirmation["title"]
+ assert_equal I18n.t("shared.custom_confirm.default_btn_text", locale: :de), confirmation["confirmText"]
+ end
+
test "cost basis editor shows a stored zero basis instead of placeholders" do
@holding.update!(qty: 10, cost_basis: 0, cost_basis_locked: true)