aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
authorCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-12-12 00:20:07 -0200
committerCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2013-01-08 09:15:20 -0200
commitc67005f221f102fe2caca231027d9b11cf630484 (patch)
tree06bcbb633c6c2c4808091fe9ccf4dd8a164b06d1 /actionpack/test
parent77516a712b5f10d14727d807697272b4607db7bc (diff)
downloadrails-c67005f221f102fe2caca231027d9b11cf630484.tar.gz
rails-c67005f221f102fe2caca231027d9b11cf630484.tar.bz2
rails-c67005f221f102fe2caca231027d9b11cf630484.zip
Do not generate local vars for partials without object or collection
Previously rendering a partial without giving :object or :collection would generate a local variable with the partial name by default. This was noticed due to warnings in Ruby 2.0 of not used variables, which turned out to be the generation of not used variables inside partials that do not contain objects related to them.
Diffstat (limited to 'actionpack/test')
-rw-r--r--actionpack/test/fixtures/test/_partial_name_local_variable.erb1
-rw-r--r--actionpack/test/template/render_test.rb7
2 files changed, 8 insertions, 0 deletions
diff --git a/actionpack/test/fixtures/test/_partial_name_local_variable.erb b/actionpack/test/fixtures/test/_partial_name_local_variable.erb
new file mode 100644
index 0000000000..cc3a91c89f
--- /dev/null
+++ b/actionpack/test/fixtures/test/_partial_name_local_variable.erb
@@ -0,0 +1 @@
+<%= partial_name_local_variable %>
diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb
index 9fb26e32b1..8111e58527 100644
--- a/actionpack/test/template/render_test.rb
+++ b/actionpack/test/template/render_test.rb
@@ -318,6 +318,13 @@ module RenderTestCases
@controller_view.render(customers, :greeting => "Hello")
end
+ def test_render_partial_without_object_or_collection_does_not_generate_partial_name_local_variable
+ exception = assert_raises ActionView::Template::Error do
+ @controller_view.render("partial_name_local_variable")
+ end
+ assert_match "undefined local variable or method `partial_name_local_variable'", exception.message
+ end
+
# TODO: The reason for this test is unclear, improve documentation
def test_render_partial_and_fallback_to_layout
assert_equal "Before (Josh)\n\nAfter", @view.render(:partial => "test/layout_for_partial", :locals => { :name => "Josh" })