Skip to content

Commit

Permalink
Render menus for current site only
Browse files Browse the repository at this point in the history
Menus should be rendered for current site only.

Closes #1734
  • Loading branch information
tvdeyen committed Feb 26, 2020
1 parent 35e0e99 commit 7e94d2e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/helpers/alchemy/pages_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions spec/helpers/alchemy/pages_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7e94d2e

Please sign in to comment.