diff options
Diffstat (limited to 'actionpack/test/template/erb')
-rw-r--r-- | actionpack/test/template/erb/form_for_test.rb | 11 | ||||
-rw-r--r-- | actionpack/test/template/erb/helper.rb | 30 | ||||
-rw-r--r-- | actionpack/test/template/erb/tag_helper_test.rb | 58 |
3 files changed, 59 insertions, 40 deletions
diff --git a/actionpack/test/template/erb/form_for_test.rb b/actionpack/test/template/erb/form_for_test.rb new file mode 100644 index 0000000000..482dbb0287 --- /dev/null +++ b/actionpack/test/template/erb/form_for_test.rb @@ -0,0 +1,11 @@ +require "abstract_unit" +require "template/erb/helper" + +module ERBTest + class TagHelperTest < BlockTestCase + test "form_for works" do + output = render_content "form_for(:staticpage, :url => {:controller => 'blah', :action => 'update'})", "" + assert_equal "<form action=\"/blah/update\" method=\"post\"></form>", output + end + end +end
\ No newline at end of file diff --git a/actionpack/test/template/erb/helper.rb b/actionpack/test/template/erb/helper.rb new file mode 100644 index 0000000000..7147178849 --- /dev/null +++ b/actionpack/test/template/erb/helper.rb @@ -0,0 +1,30 @@ +module ERBTest + class ViewContext + mock_controller = Class.new do + include SharedTestRoutes.url_helpers + end + + include ActionView::Helpers::TagHelper + include ActionView::Helpers::JavaScriptHelper + include ActionView::Helpers::FormHelper + + attr_accessor :output_buffer + + def protect_against_forgery?() false end + + define_method(:controller) do + mock_controller.new + end + end + + class BlockTestCase < ActiveSupport::TestCase + def render_content(start, inside) + template = block_helper(start, inside) + ActionView::Template::Handlers::Erubis.new(template).evaluate(ViewContext.new) + end + + def block_helper(str, rest) + "<%= #{str} do %>#{rest}<% end %>" + end + end +end
\ No newline at end of file diff --git a/actionpack/test/template/erb/tag_helper_test.rb b/actionpack/test/template/erb/tag_helper_test.rb index cc96a43901..64a88bde1d 100644 --- a/actionpack/test/template/erb/tag_helper_test.rb +++ b/actionpack/test/template/erb/tag_helper_test.rb @@ -1,66 +1,44 @@ require "abstract_unit" +require "template/erb/helper" module ERBTest - class ViewContext - mock_controller = Class.new do - include SharedTestRoutes.url_helpers - end - - include ActionView::Helpers::TagHelper - include ActionView::Helpers::JavaScriptHelper - include ActionView::Helpers::FormHelper - - attr_accessor :output_buffer - - def protect_against_forgery?() false end - - define_method(:controller) do - mock_controller.new - end - end - - class DeprecatedViewContext < ViewContext - include ActionView::Helpers::DeprecatedBlockHelpers - end - 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) + 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 - class TagHelperTest < ActiveSupport::TestCase - def context - ViewContext - end - + class TagHelperTest < BlockTestCase def block_helper(str, rest) "<%= #{str} do %>#{rest}<% end %>" end @@ -68,15 +46,15 @@ module ERBTest include SharedTagHelpers end - class DeprecatedTagHelperTest < ActiveSupport::TestCase - def context - DeprecatedViewContext - end - + class DeprecatedTagHelperTest < BlockTestCase def block_helper(str, rest) "<% __in_erb_template=true %><% #{str} do %>#{rest}<% end %>" end + def setup + @deprecated = true + end + include SharedTagHelpers end end
\ No newline at end of file |