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

Remove Page.ancestors_for #1813

Merged
merged 1 commit into from
May 6, 2020
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
6 changes: 3 additions & 3 deletions app/helpers/alchemy/pages_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def language_links(options = {})
partial: "alchemy/language_links/language",
collection: languages,
spacer_template: "alchemy/language_links/spacer",
locals: {languages: languages, options: options},
locals: { languages: languages, options: options },
)
end

Expand Down Expand Up @@ -127,8 +127,8 @@ def render_breadcrumb(options = {})
link_active_page: false,
}.merge(options)

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

if options.delete(:restricted_only)
Expand Down
8 changes: 0 additions & 8 deletions app/models/alchemy/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -256,14 +256,6 @@ def link_target_options
options
end

# Returns an array of all pages in the same branch from current.
# I.e. used to find the active page in navigation.
def ancestors_for(current)
return [] if current.nil?

current.self_and_ancestors.contentpages
end

private

# Aggregates the attributes from given source for copy of page.
Expand Down
20 changes: 0 additions & 20 deletions spec/models/alchemy/page_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -376,26 +376,6 @@ module Alchemy
end
end

describe ".ancestors_for" do
let(:lang_root) { Page.language_root_for(Language.default.id) }
let(:parent) { create(:alchemy_page, :public) }
let(:page) { create(:alchemy_page, :public, parent_id: parent.id) }

it "returns an array of all parents including self" do
expect(Page.ancestors_for(page)).to eq([lang_root, parent, page])
end

it "does not include the root page" do
expect(Page.ancestors_for(page)).not_to include(Page.root)
end

context "with current page nil" do
it "should return an empty array" do
expect(Page.ancestors_for(nil)).to eq([])
end
end
end

describe ".contentpages" do
let!(:layoutpage) do
create :alchemy_page, :public, {
Expand Down