aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorTobias Svensson <tob@tobiassvensson.co.uk>2011-11-19 13:02:56 +0000
committerTobias Svensson <tob@tobiassvensson.co.uk>2011-11-19 13:05:57 +0000
commit771635e858e486e1e9f2d181b710d81205e6bb4e (patch)
treefe53145ddd22a3e99861fd5f1600e2133ac1df62 /actionpack
parent11afb74089b0e8ad9b85de3f3fcb1f6dd179fa66 (diff)
downloadrails-771635e858e486e1e9f2d181b710d81205e6bb4e.tar.gz
rails-771635e858e486e1e9f2d181b710d81205e6bb4e.tar.bz2
rails-771635e858e486e1e9f2d181b710d81205e6bb4e.zip
Meaningful errors for unexpected partial arguments. Fixes #3573
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_view/renderer/partial_renderer.rb9
-rw-r--r--actionpack/test/template/render_test.rb7
2 files changed, 14 insertions, 2 deletions
diff --git a/actionpack/lib/action_view/renderer/partial_renderer.rb b/actionpack/lib/action_view/renderer/partial_renderer.rb
index 15cb9d0f76..54a0ba96ff 100644
--- a/actionpack/lib/action_view/renderer/partial_renderer.rb
+++ b/actionpack/lib/action_view/renderer/partial_renderer.rb
@@ -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|
diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb
index 77659918f7..c29519276d 100644
--- a/actionpack/test/template/render_test.rb
+++ b/actionpack/test/template/render_test.rb
@@ -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"