From 2437561fe87bb8547d65b322f5da81f82a41dde3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robin=20Bo=CC=88ning?= Date: Mon, 19 Apr 2021 21:05:41 +0100 Subject: [PATCH] hotfix and deprecate page_active? helper The `page_active?` helper used to depend on `Page.ancestors_for` which got removed with https://github.com/AlchemyCMS/alchemy_cms/pull/1813. This PR hotfixes `page_active?`, but since menus got introduced with https://github.com/AlchemyCMS/alchemy_cms/pull/1667 the helper is obsolete and is now marked for deletion. --- app/helpers/alchemy/pages_helper.rb | 4 +++- spec/helpers/alchemy/pages_helper_spec.rb | 8 ++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/helpers/alchemy/pages_helper.rb b/app/helpers/alchemy/pages_helper.rb index c98ee22d4c..b3580aa9ed 100644 --- a/app/helpers/alchemy/pages_helper.rb +++ b/app/helpers/alchemy/pages_helper.rb @@ -100,7 +100,9 @@ def render_menu(menu_type, options = {}) # Returns true if page is in the active branch def page_active?(page) - @_page_ancestors ||= Page.ancestors_for(@page) + Alchemy::Deprecation.warn("page_active? helper is deprecated and will be removed from Alchemy 6.0") + + @_page_ancestors ||= @page.self_and_ancestors.contentpages @_page_ancestors.include?(page) end diff --git a/spec/helpers/alchemy/pages_helper_spec.rb b/spec/helpers/alchemy/pages_helper_spec.rb index 3d93d5f8e9..965cf86465 100644 --- a/spec/helpers/alchemy/pages_helper_spec.rb +++ b/spec/helpers/alchemy/pages_helper_spec.rb @@ -14,6 +14,14 @@ module Alchemy @root_page = language_root # We need this instance variable in the helpers end + describe "page_active?" do + it "shows a deprecation warning" do + @page = public_page + expect(Alchemy::Deprecation).to receive(:warn).with /will be removed from Alchemy 6/ + helper.page_active?(public_page) + end + end + describe "#render_page_layout" do it "should render the current page layout" do @page = public_page