From e88dbbcc2249085c89ab598fca9ee3a6ab7eeaba Mon Sep 17 00:00:00 2001 From: Martin Meyerhoff Date: Thu, 16 Sep 2021 10:40:34 +0200 Subject: [PATCH] Use self_and_ancestors in page_active? helper This helper used a method that has been removed in #1813. I'm also adding some specs. --- app/helpers/alchemy/pages_helper.rb | 2 +- spec/helpers/alchemy/pages_helper_spec.rb | 31 +++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/app/helpers/alchemy/pages_helper.rb b/app/helpers/alchemy/pages_helper.rb index c98ee22d4c..7bf7ed9b20 100644 --- a/app/helpers/alchemy/pages_helper.rb +++ b/app/helpers/alchemy/pages_helper.rb @@ -100,7 +100,7 @@ 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) + @_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..e49ab053a8 100644 --- a/spec/helpers/alchemy/pages_helper_spec.rb +++ b/spec/helpers/alchemy/pages_helper_spec.rb @@ -357,5 +357,36 @@ module Alchemy expect(helper.picture_essence_caption(content)).to eq "my caption" end end + + describe "#page_active?" do + let(:child_page) { create(:alchemy_page, parent: public_page) } + + before do + @page = current_page + end + + subject { helper.page_active?(passed_page) } + + context "passed page is the current page" do + let(:passed_page) { public_page } + let(:current_page) { public_page } + + it { is_expected.to be true } + end + + context "passed page is an ancestor of the current page" do + let(:current_page) { child_page } + let(:passed_page) { public_page } + + it { is_expected.to be true } + end + + context "passed page is in another branch of the page tree" do + let(:passed_page) { create(:alchemy_page, parent: language_root) } + let(:current_page) { public_page } + + it { is_expected.to be false } + end + end end end