The personal finance app for everyone (by everyone)
Ruby
Ask before unlocking a cost basis or resetting a security (#4418)
GFR5d6ad3c96ea8
diff --git a/app/views/holdings/show.html.erb b/app/views/holdings/show.html.erbindex 2fde086f69..a9050db030 100644--- a/app/views/holdings/show.html.erb+++ b/app/views/holdings/show.html.erb@@ -212,15 +212,17 @@<h4 class="text-primary"><%= t(".security_remapped_label") %></h4><p class="text-secondary"><%= t(".provider_sent", ticker: @holding.provider_security.ticker) %></p></div>- <%= button_to t(".reset_to_provider"),- reset_security_holding_path(@holding),- method: :post,- class: "inline-flex items-center gap-1 px-3 py-2 rounded-lg text-sm font-medium text-primary button-bg-secondary-strong hover:button-bg-secondary-strong-hover",- form: { data: { turbo: false } },- data: { turbo_confirm: {- title: t(".reset_confirm_title"),- body: t(".reset_confirm_body", current: @holding.security.ticker, original: @holding.provider_security.ticker)- } } %>+ <%= render DS::Button.new(+ text: t(".reset_to_provider"),+ variant: :secondary,+ href: reset_security_holding_path(@holding),+ method: :post,+ form: { data: { turbo_frame: "_top" } },+ confirm: CustomConfirm.new(+ title: t(".reset_confirm_title"),+ body: t(".reset_confirm_body", current: @holding.security.ticker, original: @holding.provider_security.ticker)+ )+ ) %></div><% end %><% unless @holding.security.offline? %>@@ -231,16 +233,18 @@<%= t(".last_price_update") %>: <%= @last_price_updated ? l(@last_price_updated, format: :long) : t(".never") %></p></div>- <%= button_to t(".market_data_sync_button"),- sync_prices_holding_path(@holding),- method: :post,- class: "inline-flex items-center gap-1 px-3 py-2 rounded-lg text-sm font-medium text-primary button-bg-secondary-strong hover:button-bg-secondary-strong-hover",- data: { loading_button_target: "button" },- form: { data: {- controller: "loading-button",- action: "submit->loading-button#showLoading",- loading_button_loading_text_value: t(".syncing")- } } %>+ <%= render DS::Button.new(+ text: t(".market_data_sync_button"),+ variant: :secondary,+ href: sync_prices_holding_path(@holding),+ method: :post,+ data: { loading_button_target: "button" },+ form: { data: {+ controller: "loading-button",+ action: "submit->loading-button#showLoading",+ loading_button_loading_text_value: t(".syncing")+ } }+ ) %></div><% end %><% if @holding.cost_basis_locked? %>@@ -249,12 +253,14 @@<h4 class="text-primary"><%= t(".cost_basis_locked_label") %></h4><p class="text-secondary"><%= t(".cost_basis_locked_description") %></p></div>- <%= button_to t(".unlock_cost_basis"),- unlock_cost_basis_holding_path(@holding),- method: :post,- class: "inline-flex items-center gap-1 px-3 py-2 rounded-lg text-sm font-medium text-primary button-bg-secondary-strong hover:button-bg-secondary-strong-hover",- form: { data: { turbo: false } },- data: { turbo_confirm: { title: t(".unlock_confirm_title"), body: t(".unlock_confirm_body") } } %>+ <%= render DS::Button.new(+ text: t(".unlock_cost_basis"),+ variant: :secondary,+ href: unlock_cost_basis_holding_path(@holding),+ method: :post,+ form: { data: { turbo_frame: "_top" } },+ confirm: CustomConfirm.new(title: t(".unlock_confirm_title"), body: t(".unlock_confirm_body"))+ ) %></div><% end %><% if @holding.account.can_delete_holdings? %>diff --git a/test/system/holding_drawer_actions_test.rb b/test/system/holding_drawer_actions_test.rbnew file mode 100644index 0000000000..773c1d2d5b--- /dev/null+++ b/test/system/holding_drawer_actions_test.rb@@ -0,0 +1,55 @@+require "application_system_test_case"++class HoldingDrawerActionsTest < ApplicationSystemTestCase+ setup do+ sign_in @user = users(:family_admin)+ @user.update!(show_sidebar: false, show_ai_sidebar: false)++ @holding = holdings(:one)+ end++ test "unlocking a cost basis asks first and keeps the lock when cancelled" do+ @holding.update!(cost_basis: 12.5, cost_basis_source: "manual", cost_basis_locked: true)++ visit holding_path(@holding)+ click_on I18n.t("holdings.show.unlock_cost_basis")++ within "#confirm-dialog" do+ assert_text I18n.t("holdings.show.unlock_confirm_title")+ assert_selector "button[value=confirm]", text: I18n.t("shared.custom_confirm.default_btn_text")+ find("button[value=cancel]").click+ end++ assert_no_selector "#confirm-dialog[open]"+ assert @holding.reload.cost_basis_locked?++ click_on I18n.t("holdings.show.unlock_cost_basis")+ within("#confirm-dialog") { find("button[value=confirm]").click }++ assert_text I18n.t("holdings.unlock_cost_basis.success")+ assert_not @holding.reload.cost_basis_locked?+ end++ test "resetting a remapped security asks first and keeps the mapping when cancelled" do+ @holding.account.update!(plaid_account: plaid_accounts(:one))+ @holding.update!(security: securities(:msft), provider_security: securities(:aapl), security_locked: true)++ visit holding_path(@holding)+ click_on I18n.t("holdings.show.reset_to_provider")++ within "#confirm-dialog" do+ assert_text I18n.t("holdings.show.reset_confirm_title")+ assert_selector "button[value=confirm]", text: I18n.t("shared.custom_confirm.default_btn_text")+ find("button[value=cancel]").click+ end++ assert_no_selector "#confirm-dialog[open]"+ assert_equal securities(:msft), @holding.reload.security++ click_on I18n.t("holdings.show.reset_to_provider")+ within("#confirm-dialog") { find("button[value=confirm]").click }++ assert_text I18n.t("holdings.reset_security.success")+ assert_equal securities(:aapl), @holding.reload.security+ end+end