Merge pull request #3695 from tobiassvn/partial_path_error
Meaningful errors for unexpected partial arguments. Fixes #3573
This commit is contained in:
commit
bc04455f10
|
@ -366,8 +366,13 @@ module ActionView
|
|||
path = if object.respond_to?(:to_partial_path)
|
||||
object.to_partial_path
|
||||
else
|
||||
ActiveSupport::Deprecation.warn "ActiveModel-compatible objects whose classes return a #model_name that responds to #partial_path are deprecated. Please respond to #to_partial_path directly instead."
|
||||
object.class.model_name.partial_path
|
||||
klass = object.class
|
||||
if klass.respond_to?(:model_name)
|
||||
ActiveSupport::Deprecation.warn "ActiveModel-compatible objects whose classes return a #model_name that responds to #partial_path are deprecated. Please respond to #to_partial_path directly instead."
|
||||
klass.model_name.partial_path
|
||||
else
|
||||
raise ArgumentError.new("'#{object.inspect}' is not an ActiveModel-compatible object that returns a valid partial path.")
|
||||
end
|
||||
end
|
||||
|
||||
@partial_names[path] ||= path.dup.tap do |object_path|
|
||||
|
|
|
@ -142,6 +142,13 @@ module RenderTestCases
|
|||
"and is followed by any combinations of letters, numbers, or underscores.", e.message
|
||||
end
|
||||
|
||||
def test_render_partial_with_incompatible_object
|
||||
@view.render(:partial => nil)
|
||||
flunk "Render did not raise ArgumentError"
|
||||
rescue ArgumentError => e
|
||||
assert_equal "'#{nil.inspect}' is not an ActiveModel-compatible object that returns a valid partial path.", e.message
|
||||
end
|
||||
|
||||
def test_render_partial_with_errors
|
||||
@view.render(:partial => "test/raise")
|
||||
flunk "Render did not raise Template::Error"
|
||||
|
|
Loading…
Reference in New Issue