From 1b4eba51fe12587a044d90c24d038ceb880c13db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janko=20Marohni=C4=87?= Date: Mon, 9 Dec 2024 11:45:17 +0100 Subject: [PATCH] Raise error when attempting to render, but rendering was disabled --- lib/rodauth.rb | 2 ++ lib/rodauth/features/base.rb | 4 ++++ spec/rodauth_spec.rb | 8 ++++++++ 3 files changed, 14 insertions(+) diff --git a/lib/rodauth.rb b/lib/rodauth.rb index fea7b663..e8f75ea4 100644 --- a/lib/rodauth.rb +++ b/lib/rodauth.rb @@ -3,6 +3,8 @@ require 'securerandom' module Rodauth + class ConfigurationError < StandardError; end + def self.lib(opts={}, &block) require 'roda' c = Class.new(Roda) diff --git a/lib/rodauth/features/base.rb b/lib/rodauth/features/base.rb index bb74e367..ac74a8bb 100644 --- a/lib/rodauth/features/base.rb +++ b/lib/rodauth/features/base.rb @@ -930,6 +930,10 @@ def _template_opts(opts, page) end def _view(meth, page) + unless scope.respond_to?(meth) + raise ConfigurationError, "attempted to render a built-in view/email template (#{page.inspect}), but rendering is disabled" + end + scope.send(meth, _view_opts(page)) end end diff --git a/spec/rodauth_spec.rb b/spec/rodauth_spec.rb index c52e5eaa..9a05b2d5 100644 --- a/spec/rodauth_spec.rb +++ b/spec/rodauth_spec.rb @@ -856,6 +856,14 @@ def foo c.ancestors.map(&:to_s).wont_include 'Roda::RodaPlugins::RouteCsrf::InstanceMethods' end + it "raises error when rendering is disabled" do + c = Class.new(Roda) + c.plugin(:rodauth, :render=>false){} + rodauth = c.new({}).rodauth + error = proc{rodauth.render("login")}.must_raise Rodauth::ConfigurationError + error.message.must_include "attempted to render" + end + it "should inherit rodauth configuration in subclass" do auth_class = nil no_freeze!