Skip to content

Commit

Permalink
Raise error when attempting to render, but rendering was disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
janko committed Dec 10, 2024
1 parent c85e485 commit eb2f7d7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/rodauth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
require 'securerandom'

module Rodauth
class ConfigurationError < StandardError; end

def self.lib(opts={}, &block)
require 'roda'
c = Class.new(Roda)
Expand Down
4 changes: 4 additions & 0 deletions lib/rodauth/features/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions spec/rodauth_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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::Error
error.message.must_include "attempted to render"
end

it "should inherit rodauth configuration in subclass" do
auth_class = nil
no_freeze!
Expand Down

0 comments on commit eb2f7d7

Please sign in to comment.