Skip to content

Commit

Permalink
Remove Page.ancestors_for (AlchemyCMS#1813)
Browse files Browse the repository at this point in the history
Its only used by the render_breadcrumb helper and that could just use the self_and_ancestors scope.
  • Loading branch information
tvdeyen authored May 6, 2020
1 parent 8b7cd55 commit 19aa55f
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 31 deletions.
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

0 comments on commit 19aa55f

Please sign in to comment.