Merge pull request #50699 from jonathanhefner/follow-up-50665

Do not mask `NoMethodError` from within `render_in`
This commit is contained in:
Jonathan Hefner 2024-01-10 13:46:40 -06:00 committed by GitHub
commit c66b655bf8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View File

@ -14,8 +14,12 @@ module ActionView
def render(context, *args)
@renderable.render_in(context)
rescue NoMethodError
rescue NoMethodError => error
if error.name == :render_in
raise ArgumentError, "'#{@renderable.inspect}' is not a renderable object. It must implement #render_in."
else
raise
end
end
def format

View File

@ -312,6 +312,15 @@ module RenderTestCases
end
end
def test_render_renderable_does_not_mask_nomethoderror_from_within_render_in
renderable = Object.new
renderable.define_singleton_method(:render_in) { |*| nil.foo }
assert_raises NoMethodError, match: "undefined method `foo' for nil" do
@view.render renderable: renderable
end
end
def test_render_partial_starting_with_a_capital
assert_nothing_raised { @view.render(partial: "test/FooBar") }
end