From 7e94d2e3f6f72715418b23ca2f023b135c95c8ac Mon Sep 17 00:00:00 2001 From: Thomas von Deyen Date: Wed, 26 Feb 2020 10:27:41 +0100 Subject: [PATCH] Render menus for current site only Menus should be rendered for current site only. Closes #1734 --- app/helpers/alchemy/pages_helper.rb | 2 +- spec/helpers/alchemy/pages_helper_spec.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/helpers/alchemy/pages_helper.rb b/app/helpers/alchemy/pages_helper.rb index 8c2f02e7fa..384c8f2c6f 100644 --- a/app/helpers/alchemy/pages_helper.rb +++ b/app/helpers/alchemy/pages_helper.rb @@ -188,7 +188,7 @@ def render_navigation(options = {}, html_options = {}) # @param [String] - Name of the menu # @param [Hash] - A set of options available in your menu partials def render_menu(name, options = {}) - root_node = Alchemy::Node.roots.find_by(name: name) + root_node = Alchemy::Node.roots.find_by(name: name, site: Alchemy::Site.current) if root_node.nil? warning("Menu with name #{name} not found!") return diff --git a/spec/helpers/alchemy/pages_helper_spec.rb b/spec/helpers/alchemy/pages_helper_spec.rb index 9a6d79f619..a6b4c5edfc 100644 --- a/spec/helpers/alchemy/pages_helper_spec.rb +++ b/spec/helpers/alchemy/pages_helper_spec.rb @@ -73,6 +73,18 @@ module Alchemy context 'if menu does not exist' do it { is_expected.to be_nil } end + + context 'with multiple sites' do + let!(:site_2) { create(:alchemy_site, host: 'another-site.com') } + let!(:menu) { create(:alchemy_node, name: name, site: Alchemy::Site.current) } + let!(:node) { create(:alchemy_node, parent: menu, url: '/default-site') } + let!(:menu_2) { create(:alchemy_node, name: name, site: site_2) } + let!(:node_2) { create(:alchemy_node, parent: menu_2, site: site_2, url: '/site-2') } + + it 'renders menu from current site' do + is_expected.to have_selector('ul.nav > li.nav-item > a.nav-link[href="/default-site"]') + end + end end describe "#render_navigation" do