From 19aa55f5cc9b6aabbb73ef016f8501bf57911249 Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Wed, 6 May 2020 13:02:56 +0200 Subject: [PATCH] Remove Page.ancestors_for (#1813) Its only used by the render_breadcrumb helper and that could just use the self_and_ancestors scope. --- app/helpers/alchemy/pages_helper.rb | 6 +++--- app/models/alchemy/page.rb | 8 -------- spec/models/alchemy/page_spec.rb | 20 -------------------- 3 files changed, 3 insertions(+), 31 deletions(-) diff --git a/app/helpers/alchemy/pages_helper.rb b/app/helpers/alchemy/pages_helper.rb index eaea9bf733..42a2473d37 100644 --- a/app/helpers/alchemy/pages_helper.rb +++ b/app/helpers/alchemy/pages_helper.rb @@ -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 @@ -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) diff --git a/app/models/alchemy/page.rb b/app/models/alchemy/page.rb index 9a2107589f..93807c0754 100644 --- a/app/models/alchemy/page.rb +++ b/app/models/alchemy/page.rb @@ -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. diff --git a/spec/models/alchemy/page_spec.rb b/spec/models/alchemy/page_spec.rb index 10c0a1ff8e..b68fa3720a 100644 --- a/spec/models/alchemy/page_spec.rb +++ b/spec/models/alchemy/page_spec.rb @@ -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, {