Merge pull request #50665 from seanpdoyle/action-view-renderable-argument-error

Raise `ArgumentError` if `:renderable` object does not respond to `#render_in`
This commit is contained in:
Rafael Mendonça França 2024-01-09 17:03:24 -05:00 committed by GitHub
commit f3d96c2aa4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 24 additions and 3 deletions

View File

@ -1,3 +1,7 @@
* Raise `ArgumentError` if `:renderable` object does not respond to `#render_in`
*Sean Doyle*
* Add the `nonce: true` option for `stylesheet_link_tag` helper to support automatic nonce generation for Content Security Policy.
Works the same way as `javascript_include_tag nonce: true` does.

View File

@ -79,7 +79,7 @@ module ActionView
path = if object.respond_to?(:to_partial_path)
object.to_partial_path
else
raise ArgumentError.new("'#{object.inspect}' is not an ActiveModel-compatible object. It must implement :to_partial_path.")
raise ArgumentError.new("'#{object.inspect}' is not an ActiveModel-compatible object. It must implement #to_partial_path.")
end
if view.prefix_partial_path_with_controller_namespace

View File

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

View File

@ -293,8 +293,23 @@ module RenderTestCases
end
def test_render_partial_with_incompatible_object
e = assert_raises(ArgumentError) { @view.render(partial: nil) }
assert_equal "'#{nil.inspect}' is not an ActiveModel-compatible object. It must implement :to_partial_path.", e.message
assert_raises ArgumentError, match: "'#{nil.inspect}' is not an ActiveModel-compatible object. It must implement #to_partial_path." do
@view.render(partial: nil)
end
end
def test_render_renderable_with_nil
assert_raises ArgumentError, match: "'#{nil.inspect}' is not a renderable object. It must implement #render_in." do
@view.render renderable: nil
end
end
def test_render_renderable_with_incompatible_object
object = Object.new
assert_raises ArgumentError, match: "'#{object.inspect}' is not a renderable object. It must implement #render_in." do
@view.render renderable: object
end
end
def test_render_partial_starting_with_a_capital