aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/template
diff options
context:
space:
mode:
authorCarlhuda <carlhuda@engineyard.com>2010-03-15 11:58:05 -0700
committerCarlhuda <carlhuda@engineyard.com>2010-03-15 14:50:43 -0700
commit9de83050d3a4b260d4aeb5d09ec4eb64f913ba64 (patch)
tree1688303e527eec441a5ec79011f06907dfe5a264 /actionpack/test/template
parent1f2738261f3c3c061540bb20e3a1edec96b76034 (diff)
downloadrails-9de83050d3a4b260d4aeb5d09ec4eb64f913ba64.tar.gz
rails-9de83050d3a4b260d4aeb5d09ec4eb64f913ba64.tar.bz2
rails-9de83050d3a4b260d4aeb5d09ec4eb64f913ba64.zip
Add deprecation notices for <% %>.
* The approach is to compile <% %> into a method call that checks whether the value returned from a block is a String. If it is, it concats to the buffer and prints a deprecation warning. * <%= %> uses exactly the same logic to compile the template, which first checks to see whether it's compiling a block. * This should have no impact on other uses of block in templates. For instance, in <% [1,2,3].each do |i| %><%= i %><% end %>, the call to each returns an Array, not a String, so the result is not concatenated * In two cases (#capture and #cache), a String can be returned that should *never* be concatenated. We have temporarily created a String subclass called NonConcattingString which behaves (and is serialized) identically to String, but is not concatenated by the code that handles deprecated <% %> block helpers. Once we remove support for <% %> block helpers, we can remove NonConcattingString.
Diffstat (limited to 'actionpack/test/template')
-rw-r--r--actionpack/test/template/erb/tag_helper_test.rb24
-rw-r--r--actionpack/test/template/render_test.rb8
2 files changed, 26 insertions, 6 deletions
diff --git a/actionpack/test/template/erb/tag_helper_test.rb b/actionpack/test/template/erb/tag_helper_test.rb
index cc96a43901..b5b7ae87de 100644
--- a/actionpack/test/template/erb/tag_helper_test.rb
+++ b/actionpack/test/template/erb/tag_helper_test.rb
@@ -20,7 +20,7 @@ module ERBTest
end
class DeprecatedViewContext < ViewContext
- include ActionView::Helpers::DeprecatedBlockHelpers
+ # include ActionView::Helpers::DeprecatedBlockHelpers
end
module SharedTagHelpers
@@ -31,28 +31,36 @@ module ERBTest
ActionView::Template::Handlers::Erubis.new(template).evaluate(context.new)
end
+ def maybe_deprecated
+ if @deprecated
+ assert_deprecated { yield }
+ else
+ yield
+ end
+ end
+
test "percent equals works for content_tag and does not require parenthesis on method call" do
- assert_equal "<div>Hello world</div>", render_content("content_tag :div", "Hello world")
+ maybe_deprecated { assert_equal "<div>Hello world</div>", render_content("content_tag :div", "Hello world") }
end
test "percent equals works for javascript_tag" do
expected_output = "<script type=\"text/javascript\">\n//<![CDATA[\nalert('Hello')\n//]]>\n</script>"
- assert_equal expected_output, render_content("javascript_tag", "alert('Hello')")
+ maybe_deprecated { assert_equal expected_output, render_content("javascript_tag", "alert('Hello')") }
end
test "percent equals works for javascript_tag with options" do
expected_output = "<script id=\"the_js_tag\" type=\"text/javascript\">\n//<![CDATA[\nalert('Hello')\n//]]>\n</script>"
- assert_equal expected_output, render_content("javascript_tag(:id => 'the_js_tag')", "alert('Hello')")
+ maybe_deprecated { assert_equal expected_output, render_content("javascript_tag(:id => 'the_js_tag')", "alert('Hello')") }
end
test "percent equals works with form tags" do
expected_output = "<form action=\"foo\" method=\"post\">hello</form>"
- assert_equal expected_output, render_content("form_tag('foo')", "<%= 'hello' %>")
+ maybe_deprecated { assert_equal expected_output, render_content("form_tag('foo')", "<%= 'hello' %>") }
end
test "percent equals works with fieldset tags" do
expected_output = "<fieldset><legend>foo</legend>hello</fieldset>"
- assert_equal expected_output, render_content("field_set_tag('foo')", "<%= 'hello' %>")
+ maybe_deprecated { assert_equal expected_output, render_content("field_set_tag('foo')", "<%= 'hello' %>") }
end
end
@@ -77,6 +85,10 @@ module ERBTest
"<% __in_erb_template=true %><% #{str} do %>#{rest}<% end %>"
end
+ def setup
+ @deprecated = true
+ end
+
include SharedTagHelpers
end
end \ No newline at end of file
diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb
index cea8ab1bce..e66202e8fe 100644
--- a/actionpack/test/template/render_test.rb
+++ b/actionpack/test/template/render_test.rb
@@ -228,6 +228,14 @@ module RenderTestCases
@view.render(:file => "test/hello_world.erb", :layout => "layouts/yield")
end
+ # TODO: Move to deprecated_tests.rb
+ def test_render_with_nested_layout_deprecated
+ assert_deprecated do
+ assert_equal %(<title>title</title>\n\n\n<div id="column">column</div>\n<div id="content">content</div>\n),
+ @view.render(:file => "test/deprecated_nested_layout.erb", :layout => "layouts/yield")
+ end
+ end
+
def test_render_with_nested_layout
assert_equal %(<title>title</title>\n\n\n<div id="column">column</div>\n<div id="content">content</div>\n),
@view.render(:file => "test/nested_layout.erb", :layout => "layouts/yield")