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 7, 2024
1 parent 56a2ae3 commit 6793568
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.env.production?
warning <<~WARN
Menu partial not found for #{menu_type}.
#{error}
WARN
else
raise error
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.env).to receive(:production?).and_return(true) }

it { is_expected.to be_nil }
end

context "in dev or test environment" do
before { allow(Rails.env).to receive(:production?).and_return(false) }

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

Expand Down

0 comments on commit 6793568

Please sign in to comment.