Skip to content

Commit

Permalink
Merge pull request #2194 from mamhoff/fix-5.1-stable-page-active
Browse files Browse the repository at this point in the history
Use self_and_ancestors in page_active? helper
  • Loading branch information
tvdeyen authored Sep 17, 2021
2 parents d53c938 + e88dbbc commit d25b341
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.contentpages
@_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 d25b341

Please sign in to comment.