Skip to content

Commit

Permalink
Use self_and_ancestors in page_active? helper
Browse files Browse the repository at this point in the history
This helper used a method that has been removed in AlchemyCMS#1813.
I'm also adding some specs.
  • Loading branch information
mamhoff committed Sep 16, 2021
1 parent 488709c commit c62cc4a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/helpers/alchemy/pages_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
@_page_ancestors.include?(page)
end

Expand Down
31 changes: 31 additions & 0 deletions spec/helpers/alchemy/pages_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c62cc4a

Please sign in to comment.