aboutsummaryrefslogblamecommitdiffstats
path: root/actionpack/test/template/erb/tag_helper_test.rb
blob: a384e947661bf4f64d272d85b3024c2476fc4643 (plain) (tree)
1
2
3
4
5
6
7
8
9
                       
                             

              
                                     
 

                                              
                                                                                                  
                                                                                              



                                                                                                          
                                                                                      



                                                                                                                            
                                                                                                           
       

                                                 
                                                                              
                                                                                       



                                                                        
                                                                                            
       
     
  
require "abstract_unit"
require "template/erb/helper"

module ERBTest
  class TagHelperTest < BlockTestCase

    extend ActiveSupport::Testing::Declarative

    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 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

    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