aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/test/template/erb
diff options
context:
space:
mode:
Diffstat (limited to 'actionview/test/template/erb')
-rw-r--r--actionview/test/template/erb/form_for_test.rb17
-rw-r--r--actionview/test/template/erb/helper.rb31
-rw-r--r--actionview/test/template/erb/tag_helper_test.rb32
3 files changed, 80 insertions, 0 deletions
diff --git a/actionview/test/template/erb/form_for_test.rb b/actionview/test/template/erb/form_for_test.rb
new file mode 100644
index 0000000000..b3a47e17a4
--- /dev/null
+++ b/actionview/test/template/erb/form_for_test.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+require "abstract_unit"
+require "template/erb/helper"
+
+module ERBTest
+ class TagHelperTest < BlockTestCase
+ test "form_for works" do
+ routes = ActionDispatch::Routing::RouteSet.new
+ routes.draw do
+ get "/blah/update", to: "blah#update"
+ end
+ output = render_content "form_for(:staticpage, :url => {:controller => 'blah', :action => 'update'})", "", routes
+ assert_match %r{<form.*action="/blah/update".*method="post">.*</form>}, output
+ end
+ end
+end
diff --git a/actionview/test/template/erb/helper.rb b/actionview/test/template/erb/helper.rb
new file mode 100644
index 0000000000..727cc3dcf2
--- /dev/null
+++ b/actionview/test/template/erb/helper.rb
@@ -0,0 +1,31 @@
+# frozen_string_literal: true
+
+module ERBTest
+ class ViewContext
+ include ActionView::Helpers::UrlHelper
+ include ActionView::Helpers::TagHelper
+ include ActionView::Helpers::JavaScriptHelper
+ include ActionView::Helpers::FormHelper
+
+ attr_accessor :output_buffer, :controller
+
+ def protect_against_forgery?() false end
+ end
+
+ class BlockTestCase < ActiveSupport::TestCase
+ def render_content(start, inside, routes = nil)
+ routes ||= ActionDispatch::Routing::RouteSet.new.tap do |rs|
+ rs.draw { }
+ end
+ context = Class.new(ViewContext) {
+ include routes.url_helpers
+ }.new
+ template = block_helper(start, inside)
+ ActionView::Template::Handlers::ERB.erb_implementation.new(template).evaluate(context)
+ end
+
+ def block_helper(str, rest)
+ "<%= #{str} do %>#{rest}<% end %>"
+ end
+ end
+end
diff --git a/actionview/test/template/erb/tag_helper_test.rb b/actionview/test/template/erb/tag_helper_test.rb
new file mode 100644
index 0000000000..24a7592950
--- /dev/null
+++ b/actionview/test/template/erb/tag_helper_test.rb
@@ -0,0 +1,32 @@
+# frozen_string_literal: true
+
+require "abstract_unit"
+require "template/erb/helper"
+
+module ERBTest
+ class TagHelperTest < BlockTestCase
+ 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")
+ end
+
+ test "percent equals works for javascript_tag" do
+ expected_output = "<script>\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\">\n//<![CDATA[\nalert('Hello')\n//]]>\n</script>"
+ 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 = %r{<form.*action="/foo".*method="post">.*hello*</form>}
+ assert_match 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' %>")
+ end
+ end
+end