The personal finance app for everyone (by everyone)
Ruby
Link the parent breadcrumb on account and SSO provider pages (#4373)
jaysbeekay6f670ebe713d
diff --git a/app/controllers/accounts_controller.rb b/app/controllers/accounts_controller.rbindex 72bdf792fe..0b6dbb3e75 100644--- a/app/controllers/accounts_controller.rb+++ b/app/controllers/accounts_controller.rb@@ -83,6 +83,11 @@ class AccountsController < ApplicationControllerenddef show+ @breadcrumbs = [+ [ t("breadcrumbs.home"), root_path ],+ [ t("breadcrumbs.accounts"), accounts_path ],+ [ @account.name, nil ]+ ]@chart_view = params[:chart_view] || "balance"@tab = params[:tab]# One reference date for everything on the page that is date-sensitive:diff --git a/app/controllers/admin/sso_providers_controller.rb b/app/controllers/admin/sso_providers_controller.rbindex ca493380bc..0e4c3a897c 100644--- a/app/controllers/admin/sso_providers_controller.rb+++ b/app/controllers/admin/sso_providers_controller.rb@@ -22,6 +22,7 @@ module Admindef new@sso_provider = SsoProvider.newauthorize @sso_provider+ set_form_breadcrumbs(:new)enddef create@@ -38,12 +39,14 @@ module Adminclear_provider_cacheredirect_to admin_sso_providers_path, notice: t(".success")else+ set_form_breadcrumbs(:new)render :new, status: :unprocessable_entityendenddef editauthorize @sso_provider+ set_form_breadcrumbs(:edit)enddef update@@ -61,6 +64,7 @@ module Adminclear_provider_cacheredirect_to admin_sso_providers_path, notice: t(".success")else+ set_form_breadcrumbs(:edit)render :edit, status: :unprocessable_entityendend@@ -104,6 +108,16 @@ module Admin@sso_provider = SsoProvider.find(params[:id])end+ # The form pages sit under the providers list, so the trail links back+ # to it and ends on the form's own title.+ def set_form_breadcrumbs(action)+ @breadcrumbs = [+ [ t("breadcrumbs.home"), root_path ],+ [ t("breadcrumbs.sso_providers"), admin_sso_providers_path ],+ [ t("admin.sso_providers.#{action}.title"), nil ]+ ]+ end+def sso_provider_paramsparams.require(:sso_provider).permit(:strategy,diff --git a/test/controllers/accounts_controller_test.rb b/test/controllers/accounts_controller_test.rbindex 385edc4df2..e1c3706cf9 100644--- a/test/controllers/accounts_controller_test.rb+++ b/test/controllers/accounts_controller_test.rb@@ -377,6 +377,24 @@ class AccountsControllerTest < ActionDispatch::IntegrationTestassert_includes response.body, titleend+ # The default trail ends on "Accounts", which is never a link, so an account's+ # page had no way back to the accounts list.+ test "show links the Accounts crumb back to the accounts list" do+ get account_url(@account)++ assert_response :success+ assert_select "[data-breadcrumbs] a[href=?]", accounts_path, text: I18n.t("breadcrumbs.accounts")+ assert_select "[data-breadcrumbs] > span:last-child", text: @account.name+ end++ test "the accounts list itself stays the unlinked current crumb" do+ get accounts_url++ assert_response :success+ assert_select "[data-breadcrumbs] a[href=?]", accounts_path, count: 0+ assert_select "[data-breadcrumbs] > span:last-child", text: I18n.t("breadcrumbs.accounts")+ end+test "index offers a QR login on a Trade Republic connection that needs one" doitem = trade_republic_items(:configured_item)item.update!(session_blob: trade_republic_session_blob(expires_at: 1.minute.ago))diff --git a/test/controllers/admin/sso_providers_controller_test.rb b/test/controllers/admin/sso_providers_controller_test.rbindex 5dc95f09ec..d6caf5e8f9 100644--- a/test/controllers/admin/sso_providers_controller_test.rb+++ b/test/controllers/admin/sso_providers_controller_test.rb@@ -43,6 +43,46 @@ class Admin::SsoProvidersControllerTest < ActionDispatch::IntegrationTestassert_select "p", text: I18n.t("admin.sso_providers.edit.description", locale: :de, fallback: false, label: @provider.label)end+ # The default trail ends on the controller's name, which is never a link, so+ # the form pages had no way back to the providers list.+ test "the new page links its SSO providers crumb back to the list" do+ get new_admin_sso_provider_path++ assert_response :success+ assert_form_trail I18n.t("admin.sso_providers.new.title")+ end++ test "the edit page links its SSO providers crumb back to the list" do+ get edit_admin_sso_provider_path(@provider)++ assert_response :success+ assert_form_trail I18n.t("admin.sso_providers.edit.title")+ end++ test "a rejected create keeps the trail back to the list" do+ assert_no_difference "SsoProvider.count" do+ post admin_sso_providers_path, params: { sso_provider: { strategy: "openid_connect", name: "", label: "" } }+ end++ assert_response :unprocessable_entity+ assert_form_trail I18n.t("admin.sso_providers.new.title")+ end++ test "a rejected update keeps the trail back to the list" do+ patch admin_sso_provider_path(@provider), params: { sso_provider: { name: "" } }++ assert_response :unprocessable_entity+ assert_form_trail I18n.t("admin.sso_providers.edit.title")+ end++ test "the providers list itself stays the unlinked current crumb" do+ get admin_sso_providers_path++ assert_response :success+ assert_select "[data-breadcrumbs] a[href=?]", admin_sso_providers_path, count: 0+ assert_select "[data-breadcrumbs] > span:last-child", text: I18n.t("breadcrumbs.sso_providers")+ end+test "update persists nested default role setting" dopatch admin_sso_provider_path(@provider), params: {sso_provider: valid_update_params(settings: { default_role: "guest" })@@ -64,6 +104,11 @@ class Admin::SsoProvidersControllerTest < ActionDispatch::IntegrationTestendprivate+ def assert_form_trail(title)+ assert_select "[data-breadcrumbs] a[href=?]", admin_sso_providers_path, text: I18n.t("breadcrumbs.sso_providers")+ assert_select "[data-breadcrumbs] > span:last-child", text: title+ end+def valid_update_params(overrides = {}){strategy: @provider.strategy,