Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use self_and_ancestors in page_active? helper #2193

Merged
merged 1 commit into from
Sep 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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