aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/template
diff options
context:
space:
mode:
Diffstat (limited to 'actionpack/test/template')
-rw-r--r--actionpack/test/template/erb/tag_helper_test.rb60
-rw-r--r--actionpack/test/template/javascript_helper_test.rb12
-rw-r--r--actionpack/test/template/tag_helper_test.rb16
3 files changed, 67 insertions, 21 deletions
diff --git a/actionpack/test/template/erb/tag_helper_test.rb b/actionpack/test/template/erb/tag_helper_test.rb
new file mode 100644
index 0000000000..d9ca828b43
--- /dev/null
+++ b/actionpack/test/template/erb/tag_helper_test.rb
@@ -0,0 +1,60 @@
+require "abstract_unit"
+
+module ERBTest
+ module SharedTagHelpers
+ extend ActiveSupport::Testing::Declarative
+
+ def render_content(start, inside)
+ template = block_helper(start, inside)
+ ActionView::Template::Handlers::Erubis.new(template).evaluate(context.new)
+ end
+
+ test "percent equals works for content_tag" do
+ 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')")
+ 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')")
+ end
+ end
+
+ class TagHelperTest < ActiveSupport::TestCase
+ def context
+ Class.new do
+ include ActionView::Helpers::TagHelper
+ include ActionView::Helpers::JavaScriptHelper
+
+ attr_accessor :output_buffer
+ end
+ end
+
+ def block_helper(str, rest)
+ "<%= #{str} do %>#{rest}<% end %>"
+ end
+
+ include SharedTagHelpers
+ end
+
+ class DeprecatedTagHelperTest < ActiveSupport::TestCase
+ def context
+ Class.new do
+ include ActionView::Helpers::TagHelper
+ include ActionView::Helpers::JavaScriptHelper
+ include ActionView::Helpers::DeprecatedBlockHelpers
+ attr_accessor :output_buffer
+ end
+ end
+
+ def block_helper(str, rest)
+ "<% __in_erb_template=true %><% #{str} do %>#{rest}<% end %>"
+ end
+
+ include SharedTagHelpers
+ end
+end \ No newline at end of file
diff --git a/actionpack/test/template/javascript_helper_test.rb b/actionpack/test/template/javascript_helper_test.rb
index 6604f1c095..f49b763881 100644
--- a/actionpack/test/template/javascript_helper_test.rb
+++ b/actionpack/test/template/javascript_helper_test.rb
@@ -74,18 +74,6 @@ class JavaScriptHelperTest < ActionView::TestCase
javascript_tag("alert('hello')", :id => "the_js_tag")
end
- def test_javascript_tag_with_block_in_erb
- __in_erb_template = ''
- javascript_tag { concat "alert('hello')" }
- assert_dom_equal "<script type=\"text/javascript\">\n//<![CDATA[\nalert('hello')\n//]]>\n</script>", output_buffer
- end
-
- def test_javascript_tag_with_block_and_options_in_erb
- __in_erb_template = ''
- javascript_tag(:id => "the_js_tag") { concat "alert('hello')" }
- assert_dom_equal "<script id=\"the_js_tag\" type=\"text/javascript\">\n//<![CDATA[\nalert('hello')\n//]]>\n</script>", output_buffer
- end
-
def test_javascript_cdata_section
assert_dom_equal "\n//<![CDATA[\nalert('hello')\n//]]>\n", javascript_cdata_section("alert('hello')")
end
diff --git a/actionpack/test/template/tag_helper_test.rb b/actionpack/test/template/tag_helper_test.rb
index 3858ffde40..256d9bdcde 100644
--- a/actionpack/test/template/tag_helper_test.rb
+++ b/actionpack/test/template/tag_helper_test.rb
@@ -42,15 +42,13 @@ class TagHelperTest < ActionView::TestCase
end
def test_content_tag_with_block_in_erb
- __in_erb_template = ''
- content_tag(:div) { concat "Hello world!" }
- assert_dom_equal "<div>Hello world!</div>", output_buffer
+ buffer = content_tag(:div) { concat "Hello world!" }
+ assert_dom_equal "<div>Hello world!</div>", buffer
end
def test_content_tag_with_block_and_options_in_erb
- __in_erb_template = ''
- content_tag(:div, :class => "green") { concat "Hello world!" }
- assert_dom_equal %(<div class="green">Hello world!</div>), output_buffer
+ buffer = content_tag(:div, :class => "green") { concat "Hello world!" }
+ assert_dom_equal %(<div class="green">Hello world!</div>), buffer
end
def test_content_tag_with_block_and_options_out_of_erb
@@ -68,10 +66,10 @@ class TagHelperTest < ActionView::TestCase
output_buffer
end
+ # TAG TODO: Move this into a real template
def test_content_tag_nested_in_content_tag_in_erb
- __in_erb_template = true
- content_tag("p") { concat content_tag("b", "Hello") }
- assert_equal '<p><b>Hello</b></p>', output_buffer
+ buffer = content_tag("p") { concat content_tag("b", "Hello") }
+ assert_equal '<p><b>Hello</b></p>', buffer
end
def test_content_tag_with_escaped_array_class