Skip to content

Commit

Permalink
Helper #render_menu: Raise on missing partial in dev
Browse files Browse the repository at this point in the history
When we miss a partial, we want to know (at least in the development and
test environments).
  • Loading branch information
mamhoff committed May 8, 2024
1 parent 69c4993 commit 6e874f9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
14 changes: 9 additions & 5 deletions app/helpers/alchemy/pages_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,15 @@ def render_menu(menu_type, options = {})
end

render("alchemy/menus/#{menu_type}/wrapper", menu: root_node, options: options)
rescue ActionView::MissingTemplate => e
warning <<~WARN
Menu partial not found for #{menu_type}.
#{e}
WARN
rescue ActionView::MissingTemplate => error
if Rails.application.config.consider_all_requests_local?
raise error
else
warning <<~WARN
Menu partial not found for #{menu_type}.
#{error}
WARN
end
end

# Returns page links in a breadcrumb beginning from root to current page.
Expand Down
12 changes: 11 additions & 1 deletion spec/helpers/alchemy/pages_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,17 @@ module Alchemy
context "but the template does not exist" do
let(:menu_type) { "unknown" }

it { is_expected.to be_nil }
context "in production environment" do
before { allow(Rails.application.config).to receive(:consider_all_requests_local?).and_return(false) }

it { is_expected.to be_nil }
end

context "in dev or test environment" do
before { allow(Rails.application.config).to receive(:consider_all_requests_local?).and_return(true) }

it { expect { subject }.to raise_error(ActionView::MissingTemplate) }
end
end
end

Expand Down

0 comments on commit 6e874f9

Please sign in to comment.