diff --git a/app/helpers/alchemy/pages_helper.rb b/app/helpers/alchemy/pages_helper.rb index 73f9c26aea..733a637e85 100644 --- a/app/helpers/alchemy/pages_helper.rb +++ b/app/helpers/alchemy/pages_helper.rb @@ -64,9 +64,8 @@ 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 + error_or_warning(error, "Site layout for #{current_alchemy_site.try(:name)} not found. Please run `rails g alchemy:site_layouts`") end # Renders a menu partial @@ -87,11 +86,8 @@ 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 + error_or_warning(error, "Menu partial for #{menu_type} not found. Please run `rails g alchemy:menus`") end # Returns page links in a breadcrumb beginning from root to current page. @@ -169,5 +165,16 @@ def meta_keywords def meta_robots "#{@page.robot_index? ? "" : "no"}index, #{@page.robot_follow? ? "" : "no"}follow" end + + private + + def error_or_warning(error, message) + if Rails.application.config.consider_all_requests_local? + raise error, message + else + Rails.logger.error message + "" + end + end end end diff --git a/spec/helpers/alchemy/pages_helper_spec.rb b/spec/helpers/alchemy/pages_helper_spec.rb index 82d0613ea1..2ad20e332c 100644 --- a/spec/helpers/alchemy/pages_helper_spec.rb +++ b/spec/helpers/alchemy/pages_helper_spec.rb @@ -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.application.config).to receive(:consider_all_requests_local?).and_return(false) } + + 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.application.config).to receive(:consider_all_requests_local?).and_return(true) } + + it "raises missing template error" do + expect(helper).to receive(:current_alchemy_site).twice.and_return(default_site) + expect { helper.render_site_layout }.to raise_error(ActionView::MissingTemplate) + end end end end @@ -66,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 eq("") } + 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