mirror of https://github.com/rails/rails
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:
commit
f3d96c2aa4
|
@ -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.
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue