Skip to content

Commit

Permalink
Helper #render_site_layout: Raise in dev envs
Browse files Browse the repository at this point in the history
If we miss a partial, our specs should tell us.
  • Loading branch information
mamhoff committed May 7, 2024
1 parent 5f1790c commit 56a2ae3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
10 changes: 7 additions & 3 deletions app/helpers/alchemy/pages_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,13 @@ def render_page_layout
#
def render_site_layout(&block)
render current_alchemy_site, &block
rescue ActionView::MissingTemplate
warning("Site layout for #{current_alchemy_site.try(:name)} not found. Please run `rails g alchemy:site_layouts`")
""
rescue ActionView::MissingTemplate => error
if Rails.env.production?
warning("Site layout for #{current_alchemy_site.try(:name)} not found. Please run `rails g alchemy:site_layouts`")
""
else
raise error
end
end

# Renders a menu partial
Expand Down
19 changes: 16 additions & 3 deletions spec/helpers/alchemy/pages_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,22 @@ module Alchemy
end

context "with missing partial" do
it "returns empty string and logges warning" do
expect(helper).to receive(:current_alchemy_site).twice.and_return(default_site)
expect(helper.render_site_layout).to eq("")
context "in production environment" do
before { allow(Rails.env).to receive(:production?).and_return(true) }

it "returns empty string and logges warning" do
expect(helper).to receive(:current_alchemy_site).twice.and_return(default_site)
expect(helper.render_site_layout).to eq("")
end
end

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

it "raises missing template error" do
expect(helper).to receive(:current_alchemy_site).and_return(default_site)
expect { helper.render_site_layout }.to raise_error(ActionView::MissingTemplate)
end
end
end
end
Expand Down

0 comments on commit 56a2ae3

Please sign in to comment.