Skip to content

Commit

Permalink
Do not include unpublished pages in breadcrumb
Browse files Browse the repository at this point in the history
It does not make sense to include an unpublished
page in a breadcrumb since the user is not able to
navigate to it anyway.
  • Loading branch information
tvdeyen committed Feb 5, 2021
1 parent bd201b7 commit 018e22e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
2 changes: 1 addition & 1 deletion app/helpers/alchemy/pages_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def render_breadcrumb(options = {})

pages = options[:page].
self_and_ancestors.contentpages.
accessible_by(current_ability, :see)
published

if options.delete(:restricted_only)
pages = pages.restricted
Expand Down
43 changes: 33 additions & 10 deletions spec/helpers/alchemy/pages_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,49 +99,72 @@ module Alchemy
allow(helper).to receive(:current_ability).and_return(Alchemy::Permissions.new(user))
end

subject do
helper.render_breadcrumb(page: page)
end

it "should render a breadcrumb to current page" do
expect(helper.render_breadcrumb(page: page)).to have_selector(".active.last[contains('#{page.name}')]")
is_expected.to have_selector(".active.last[contains('#{page.name}')]")
end

context "with options[:separator] given" do
subject do
helper.render_breadcrumb(page: page, separator: "<span>###</span>")
end

it "should render a breadcrumb with an alternative separator" do
expect(helper.render_breadcrumb(page: page, separator: "<span>###</span>")).to have_selector('span[contains("###")]')
is_expected.to have_selector('span[contains("###")]')
end
end

context "with options[:reverse] set to true" do
subject do
helper.render_breadcrumb(page: page, reverse: true)
end

it "should render a breadcrumb in reversed order" do
expect(helper.render_breadcrumb(page: page, reverse: true)).to have_selector('.active.first[contains("A Public Page")]')
is_expected.to have_selector('.active.first[contains("A Public Page")]')
end
end

context "with options[:restricted_only] set to true" do
let(:user) { build(:alchemy_dummy_user) }

subject do
helper.render_breadcrumb(page: page, restricted_only: true).strip
end

it "should render a breadcrumb of restricted pages only" do
page.update_columns(restricted: true, urlname: "a-restricted-public-page", name: "A restricted Public Page", title: "A restricted Public Page")
result = helper.render_breadcrumb(page: page, restricted_only: true).strip
expect(result).to have_selector("*[contains(\"#{page.name}\")]")
expect(result).to_not have_selector("*[contains(\"#{parent.name}\")]")
is_expected.to have_selector("*[contains(\"#{page.name}\")]")
is_expected.to_not have_selector("*[contains(\"#{parent.name}\")]")
end
end

it "should render a breadcrumb of unpublished pages" do
it "should not include unpublished pages" do
page.update_columns(public_on: nil, urlname: "a-unpublic-page", name: "A Unpublic Page", title: "A Unpublic Page")
expect(helper.render_breadcrumb(page: page)).to match(/A Unpublic Page/)
is_expected.to_not match(/A Unpublic Page/)
end

context "with options[:without]" do
subject do
helper.render_breadcrumb(page: page, without: page)
end

it "should render a breadcrumb without this page" do
page.update_columns(urlname: "not-me", name: "Not Me", title: "Not Me")
expect(helper.render_breadcrumb(page: page, without: page)).not_to match(/Not Me/)
is_expected.not_to match(/Not Me/)
end
end

context "with options[:without] as array" do
subject do
helper.render_breadcrumb(page: page, without: [page])
end

it "should render a breadcrumb without these pages." do
page.update_columns(urlname: "not-me", name: "Not Me", title: "Not Me")
expect(helper.render_breadcrumb(page: page, without: [page])).not_to match(/Not Me/)
is_expected.not_to match(/Not Me/)
end
end
end
Expand Down

0 comments on commit 018e22e

Please sign in to comment.