Skip to content

Commit

Permalink
Merge pull request rails#3695 from tobiassvn/partial_path_error
Browse files Browse the repository at this point in the history
Meaningful errors for unexpected partial arguments. Fixes rails#3573
  • Loading branch information
wycats committed Nov 19, 2011
2 parents fec85cf + 771635e commit bc04455
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
9 changes: 7 additions & 2 deletions actionpack/lib/action_view/renderer/partial_renderer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -366,8 +366,13 @@ def partial_path(object = @object)
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|
Expand Down
7 changes: 7 additions & 0 deletions actionpack/test/template/render_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ def test_render_partial_with_invalid_name
"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"
Expand Down

0 comments on commit bc04455

Please sign in to comment.