2016-08-06 16:50:17 +00:00
|
|
|
require "abstract_unit"
|
2005-03-09 13:53:47 +00:00
|
|
|
|
2008-04-19 18:06:57 +00:00
|
|
|
class TagHelperTest < ActionView::TestCase
|
2011-11-30 14:38:09 +00:00
|
|
|
include RenderERBUtils
|
|
|
|
|
2008-04-19 18:06:57 +00:00
|
|
|
tests ActionView::Helpers::TagHelper
|
2004-11-24 01:04:44 +00:00
|
|
|
|
|
|
|
def test_tag
|
2007-01-05 20:32:03 +00:00
|
|
|
assert_equal "<br />", tag("br")
|
2016-08-06 17:36:34 +00:00
|
|
|
assert_equal "<br clear=\"left\" />", tag(:br, clear: "left")
|
2007-01-05 20:32:03 +00:00
|
|
|
assert_equal "<br>", tag("br", nil, true)
|
2004-11-24 01:04:44 +00:00
|
|
|
end
|
2005-03-06 11:50:41 +00:00
|
|
|
|
2016-06-27 17:00:54 +00:00
|
|
|
def test_tag_builder
|
|
|
|
assert_equal "<span></span>", tag.span
|
|
|
|
assert_equal "<span class=\"bookmark\"></span>", tag.span(class: "bookmark")
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_tag_builder_void_tag
|
|
|
|
assert_equal "<br>", tag.br
|
2016-08-06 16:50:17 +00:00
|
|
|
assert_equal "<br class=\"some_class\">", tag.br(class: "some_class")
|
2016-06-27 17:00:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_tag_builder_void_tag_with_forced_content
|
|
|
|
assert_equal "<br>some content</br>", tag.br("some content")
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_tag_builder_is_singleton
|
|
|
|
assert_equal tag, tag
|
|
|
|
end
|
|
|
|
|
2005-06-16 05:04:17 +00:00
|
|
|
def test_tag_options
|
2007-09-18 10:55:15 +00:00
|
|
|
str = tag("p", "class" => "show", :class => "elsewhere")
|
2010-09-22 19:03:39 +00:00
|
|
|
assert_match(/class="show"/, str)
|
|
|
|
assert_match(/class="elsewhere"/, str)
|
2005-06-16 05:04:17 +00:00
|
|
|
end
|
|
|
|
|
2005-07-09 17:28:35 +00:00
|
|
|
def test_tag_options_rejects_nil_option
|
2016-08-06 17:36:34 +00:00
|
|
|
assert_equal "<p />", tag("p", ignored: nil)
|
2005-07-09 17:28:35 +00:00
|
|
|
end
|
|
|
|
|
2016-06-27 17:00:54 +00:00
|
|
|
def test_tag_builder_options_rejects_nil_option
|
|
|
|
assert_equal "<p></p>", tag.p(ignored: nil)
|
|
|
|
end
|
|
|
|
|
2008-11-13 20:49:23 +00:00
|
|
|
def test_tag_options_accepts_false_option
|
2016-08-06 17:36:34 +00:00
|
|
|
assert_equal "<p value=\"false\" />", tag("p", value: false)
|
2008-11-13 20:49:23 +00:00
|
|
|
end
|
|
|
|
|
2016-06-27 17:00:54 +00:00
|
|
|
def test_tag_builder_options_accepts_false_option
|
|
|
|
assert_equal "<p value=\"false\"></p>", tag.p(value: false)
|
|
|
|
end
|
|
|
|
|
2005-07-09 17:28:35 +00:00
|
|
|
def test_tag_options_accepts_blank_option
|
2016-08-06 17:36:34 +00:00
|
|
|
assert_equal "<p included=\"\" />", tag("p", included: "")
|
2005-07-09 17:28:35 +00:00
|
|
|
end
|
|
|
|
|
2016-06-27 17:00:54 +00:00
|
|
|
def test_tag_builder_options_accepts_blank_option
|
2016-08-06 16:50:17 +00:00
|
|
|
assert_equal "<p included=\"\"></p>", tag.p(included: "")
|
2016-06-27 17:00:54 +00:00
|
|
|
end
|
|
|
|
|
2016-08-12 04:57:12 +00:00
|
|
|
def test_tag_options_accepts_symbol_option_when_not_escaping
|
|
|
|
assert_equal "<p value=\"symbol\" />", tag("p", { value: :symbol }, false, false)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_tag_options_accepts_integer_option_when_not_escaping
|
|
|
|
assert_equal "<p value=\"42\" />", tag("p", { value: 42 }, false, false)
|
|
|
|
end
|
|
|
|
|
2005-10-10 21:34:51 +00:00
|
|
|
def test_tag_options_converts_boolean_option
|
2013-06-14 22:47:21 +00:00
|
|
|
assert_dom_equal '<p disabled="disabled" itemscope="itemscope" multiple="multiple" readonly="readonly" allowfullscreen="allowfullscreen" seamless="seamless" typemustmatch="typemustmatch" sortable="sortable" default="default" inert="inert" truespeed="truespeed" />',
|
2016-08-06 17:36:34 +00:00
|
|
|
tag("p", disabled: true, itemscope: true, multiple: true, readonly: true, allowfullscreen: true, seamless: true, typemustmatch: true, sortable: true, default: true, inert: true, truespeed: true)
|
2005-10-10 21:34:51 +00:00
|
|
|
end
|
|
|
|
|
2016-06-27 17:00:54 +00:00
|
|
|
def test_tag_builder_options_converts_boolean_option
|
|
|
|
assert_dom_equal '<p disabled="disabled" itemscope="itemscope" multiple="multiple" readonly="readonly" allowfullscreen="allowfullscreen" seamless="seamless" typemustmatch="typemustmatch" sortable="sortable" default="default" inert="inert" truespeed="truespeed" />',
|
|
|
|
tag.p(disabled: true, itemscope: true, multiple: true, readonly: true, allowfullscreen: true, seamless: true, typemustmatch: true, sortable: true, default: true, inert: true, truespeed: true)
|
|
|
|
end
|
|
|
|
|
2004-11-24 01:04:44 +00:00
|
|
|
def test_content_tag
|
|
|
|
assert_equal "<a href=\"create\">Create</a>", content_tag("a", "Create", "href" => "create")
|
2009-10-07 20:31:20 +00:00
|
|
|
assert content_tag("a", "Create", "href" => "create").html_safe?
|
2005-03-06 11:50:41 +00:00
|
|
|
assert_equal content_tag("a", "Create", "href" => "create"),
|
2016-08-06 17:36:34 +00:00
|
|
|
content_tag("a", "Create", href: "create")
|
2010-02-13 21:53:26 +00:00
|
|
|
assert_equal "<p><script>evil_js</script></p>",
|
2016-08-06 16:50:17 +00:00
|
|
|
content_tag(:p, "<script>evil_js</script>")
|
2010-06-06 05:20:45 +00:00
|
|
|
assert_equal "<p><script>evil_js</script></p>",
|
2016-08-06 16:50:17 +00:00
|
|
|
content_tag(:p, "<script>evil_js</script>", nil, false)
|
2004-11-24 01:04:44 +00:00
|
|
|
end
|
2008-06-20 05:03:27 +00:00
|
|
|
|
2016-06-27 17:00:54 +00:00
|
|
|
def test_tag_builder_with_content
|
|
|
|
assert_equal "<div id=\"post_1\">Content</div>", tag.div("Content", id: "post_1")
|
|
|
|
assert tag.div("Content", id: "post_1").html_safe?
|
|
|
|
assert_equal tag.div("Content", id: "post_1"),
|
|
|
|
tag.div("Content", "id": "post_1")
|
|
|
|
assert_equal "<p><script>evil_js</script></p>",
|
|
|
|
tag.p("<script>evil_js</script>")
|
|
|
|
assert_equal "<p><script>evil_js</script></p>",
|
2016-08-06 16:50:17 +00:00
|
|
|
tag.p("<script>evil_js</script>", escape_attributes: false)
|
2016-06-27 17:00:54 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_tag_builder_nested
|
|
|
|
assert_equal "<div>content</div>",
|
|
|
|
tag.div { "content" }
|
|
|
|
assert_equal "<div id=\"header\"><span>hello</span></div>",
|
2016-08-06 16:50:17 +00:00
|
|
|
tag.div(id: "header") { |tag| tag.span "hello" }
|
2016-06-27 17:00:54 +00:00
|
|
|
assert_equal "<div id=\"header\"><div class=\"world\"><span>hello</span></div></div>",
|
2016-08-06 16:50:17 +00:00
|
|
|
tag.div(id: "header") { |tag| tag.div(class: "world") { tag.span "hello" } }
|
2016-06-27 17:00:54 +00:00
|
|
|
end
|
|
|
|
|
2008-06-20 05:03:27 +00:00
|
|
|
def test_content_tag_with_block_in_erb
|
2011-11-30 14:38:09 +00:00
|
|
|
buffer = render_erb("<%= content_tag(:div) do %>Hello world!<% end %>")
|
2010-03-10 02:00:28 +00:00
|
|
|
assert_dom_equal "<div>Hello world!</div>", buffer
|
2006-10-23 22:57:59 +00:00
|
|
|
end
|
2008-06-20 05:03:27 +00:00
|
|
|
|
2016-06-27 17:00:54 +00:00
|
|
|
def test_tag_builder_with_block_in_erb
|
|
|
|
buffer = render_erb("<%= tag.div do %>Hello world!<% end %>")
|
|
|
|
assert_dom_equal "<div>Hello world!</div>", buffer
|
|
|
|
end
|
|
|
|
|
2014-12-16 16:33:53 +00:00
|
|
|
def test_content_tag_with_block_in_erb_containing_non_displayed_erb
|
|
|
|
buffer = render_erb("<%= content_tag(:p) do %><% 1 %><% end %>")
|
|
|
|
assert_dom_equal "<p></p>", buffer
|
|
|
|
end
|
|
|
|
|
2016-06-27 17:00:54 +00:00
|
|
|
def test_tag_builder_with_block_in_erb_containing_non_displayed_erb
|
|
|
|
buffer = render_erb("<%= tag.p do %><% 1 %><% end %>")
|
|
|
|
assert_dom_equal "<p></p>", buffer
|
|
|
|
end
|
|
|
|
|
2008-06-20 05:03:27 +00:00
|
|
|
def test_content_tag_with_block_and_options_in_erb
|
2011-11-30 14:38:09 +00:00
|
|
|
buffer = render_erb("<%= content_tag(:div, :class => 'green') do %>Hello world!<% end %>")
|
2010-03-10 02:00:28 +00:00
|
|
|
assert_dom_equal %(<div class="green">Hello world!</div>), buffer
|
2006-10-23 22:57:59 +00:00
|
|
|
end
|
2008-06-20 05:03:27 +00:00
|
|
|
|
2016-06-27 17:00:54 +00:00
|
|
|
def test_tag_builder_with_block_and_options_in_erb
|
|
|
|
buffer = render_erb("<%= tag.div(class: 'green') do %>Hello world!<% end %>")
|
|
|
|
assert_dom_equal %(<div class="green">Hello world!</div>), buffer
|
|
|
|
end
|
|
|
|
|
2008-06-20 05:03:27 +00:00
|
|
|
def test_content_tag_with_block_and_options_out_of_erb
|
2016-08-06 17:36:34 +00:00
|
|
|
assert_dom_equal %(<div class="green">Hello world!</div>), content_tag(:div, class: "green") { "Hello world!" }
|
2008-06-20 05:03:27 +00:00
|
|
|
end
|
|
|
|
|
2016-06-27 17:00:54 +00:00
|
|
|
def test_tag_builder_with_block_and_options_out_of_erb
|
|
|
|
assert_dom_equal %(<div class="green">Hello world!</div>), tag.div(class: "green") { "Hello world!" }
|
|
|
|
end
|
|
|
|
|
2008-06-20 05:03:27 +00:00
|
|
|
def test_content_tag_with_block_and_options_outside_out_of_erb
|
2016-08-06 17:36:34 +00:00
|
|
|
assert_equal content_tag("a", "Create", href: "create"),
|
2008-06-20 05:03:27 +00:00
|
|
|
content_tag("a", "href" => "create") { "Create" }
|
2007-05-02 22:30:41 +00:00
|
|
|
end
|
2008-06-20 05:03:27 +00:00
|
|
|
|
2016-06-27 17:00:54 +00:00
|
|
|
def test_tag_builder_with_block_and_options_outside_out_of_erb
|
|
|
|
assert_equal tag.a("Create", href: "create"),
|
|
|
|
tag.a("href": "create") { "Create" }
|
|
|
|
end
|
|
|
|
|
2014-12-15 23:34:15 +00:00
|
|
|
def test_content_tag_with_block_and_non_string_outside_out_of_erb
|
|
|
|
assert_equal content_tag("p"),
|
|
|
|
content_tag("p") { 3.times { "do_something" } }
|
|
|
|
end
|
|
|
|
|
2016-06-27 17:00:54 +00:00
|
|
|
def test_tag_builder_with_block_and_non_string_outside_out_of_erb
|
|
|
|
assert_equal tag.p,
|
|
|
|
tag.p { 3.times { "do_something" } }
|
|
|
|
end
|
|
|
|
|
2008-06-20 05:03:27 +00:00
|
|
|
def test_content_tag_nested_in_content_tag_out_of_erb
|
|
|
|
assert_equal content_tag("p", content_tag("b", "Hello")),
|
|
|
|
content_tag("p") { content_tag("b", "Hello") },
|
|
|
|
output_buffer
|
2016-06-27 17:00:54 +00:00
|
|
|
assert_equal tag.p(tag.b("Hello")),
|
2016-08-16 07:30:11 +00:00
|
|
|
tag.p { tag.b("Hello") },
|
2016-06-27 17:00:54 +00:00
|
|
|
output_buffer
|
2008-06-20 05:03:27 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_content_tag_nested_in_content_tag_in_erb
|
2011-11-30 14:38:09 +00:00
|
|
|
assert_equal "<p>\n <b>Hello</b>\n</p>", view.render("test/content_tag_nested_in_content_tag")
|
2016-06-27 17:00:54 +00:00
|
|
|
assert_equal "<p>\n <b>Hello</b>\n</p>", view.render("test/builder_tag_nested_in_content_tag")
|
2008-06-20 05:03:27 +00:00
|
|
|
end
|
|
|
|
|
2009-08-08 21:21:25 +00:00
|
|
|
def test_content_tag_with_escaped_array_class
|
2016-08-06 17:36:34 +00:00
|
|
|
str = content_tag("p", "limelight", class: ["song", "play>"])
|
2009-08-08 21:21:25 +00:00
|
|
|
assert_equal "<p class=\"song play>\">limelight</p>", str
|
|
|
|
|
2016-08-06 17:36:34 +00:00
|
|
|
str = content_tag("p", "limelight", class: ["song", "play"])
|
2009-08-08 21:21:25 +00:00
|
|
|
assert_equal "<p class=\"song play\">limelight</p>", str
|
2014-06-11 00:33:34 +00:00
|
|
|
|
2016-08-06 17:36:34 +00:00
|
|
|
str = content_tag("p", "limelight", class: ["song", ["play"]])
|
2014-06-11 00:33:34 +00:00
|
|
|
assert_equal "<p class=\"song play\">limelight</p>", str
|
2009-08-08 21:21:25 +00:00
|
|
|
end
|
|
|
|
|
2016-06-27 17:00:54 +00:00
|
|
|
def test_tag_builder_with_escaped_array_class
|
|
|
|
str = tag.p "limelight", class: ["song", "play>"]
|
|
|
|
assert_equal "<p class=\"song play>\">limelight</p>", str
|
|
|
|
|
|
|
|
str = tag.p "limelight", class: ["song", "play"]
|
|
|
|
assert_equal "<p class=\"song play\">limelight</p>", str
|
|
|
|
|
|
|
|
str = tag.p "limelight", class: ["song", ["play"]]
|
|
|
|
assert_equal "<p class=\"song play\">limelight</p>", str
|
|
|
|
end
|
|
|
|
|
2009-08-08 21:21:25 +00:00
|
|
|
def test_content_tag_with_unescaped_array_class
|
2016-08-16 07:30:11 +00:00
|
|
|
str = content_tag("p", "limelight", { class: ["song", "play>"] }, false)
|
2009-08-08 21:21:25 +00:00
|
|
|
assert_equal "<p class=\"song play>\">limelight</p>", str
|
2014-06-11 00:33:34 +00:00
|
|
|
|
2016-08-16 07:30:11 +00:00
|
|
|
str = content_tag("p", "limelight", { class: ["song", ["play>"]] }, false)
|
2014-06-11 00:33:34 +00:00
|
|
|
assert_equal "<p class=\"song play>\">limelight</p>", str
|
|
|
|
end
|
|
|
|
|
2016-06-27 17:00:54 +00:00
|
|
|
def test_tag_builder_with_unescaped_array_class
|
|
|
|
str = tag.p "limelight", class: ["song", "play>"], escape_attributes: false
|
|
|
|
assert_equal "<p class=\"song play>\">limelight</p>", str
|
|
|
|
|
|
|
|
str = tag.p "limelight", class: ["song", ["play>"]], escape_attributes: false
|
|
|
|
assert_equal "<p class=\"song play>\">limelight</p>", str
|
|
|
|
end
|
|
|
|
|
2014-06-11 00:33:34 +00:00
|
|
|
def test_content_tag_with_empty_array_class
|
2016-08-06 17:44:11 +00:00
|
|
|
str = content_tag("p", "limelight", class: [])
|
2014-06-11 00:33:34 +00:00
|
|
|
assert_equal '<p class="">limelight</p>', str
|
|
|
|
end
|
|
|
|
|
2016-06-27 17:00:54 +00:00
|
|
|
def test_tag_builder_with_empty_array_class
|
2016-08-06 16:50:17 +00:00
|
|
|
assert_equal '<p class="">limelight</p>', tag.p("limelight", class: [])
|
2016-06-27 17:00:54 +00:00
|
|
|
end
|
|
|
|
|
2014-06-11 00:33:34 +00:00
|
|
|
def test_content_tag_with_unescaped_empty_array_class
|
2016-08-16 07:30:11 +00:00
|
|
|
str = content_tag("p", "limelight", { class: [] }, false)
|
2014-06-11 00:33:34 +00:00
|
|
|
assert_equal '<p class="">limelight</p>', str
|
2009-08-08 21:21:25 +00:00
|
|
|
end
|
|
|
|
|
2016-06-27 17:00:54 +00:00
|
|
|
def test_tag_builder_with_unescaped_empty_array_class
|
2016-08-06 16:50:17 +00:00
|
|
|
str = tag.p "limelight", class: [], escape_attributes: false
|
2016-06-27 17:00:54 +00:00
|
|
|
assert_equal '<p class="">limelight</p>', str
|
|
|
|
end
|
|
|
|
|
2012-11-01 10:49:47 +00:00
|
|
|
def test_content_tag_with_data_attributes
|
|
|
|
assert_dom_equal '<p data-number="1" data-string="hello" data-string-with-quotes="double"quote"party"">limelight</p>',
|
2016-08-06 16:50:17 +00:00
|
|
|
content_tag("p", "limelight", data: { number: 1, string: "hello", string_with_quotes: 'double"quote"party"' })
|
2012-11-01 10:49:47 +00:00
|
|
|
end
|
|
|
|
|
2016-06-27 17:00:54 +00:00
|
|
|
def test_tag_builder_with_data_attributes
|
|
|
|
assert_dom_equal '<p data-number="1" data-string="hello" data-string-with-quotes="double"quote"party"">limelight</p>',
|
2016-08-06 16:50:17 +00:00
|
|
|
tag.p("limelight", data: { number: 1, string: "hello", string_with_quotes: 'double"quote"party"' })
|
2016-06-27 17:00:54 +00:00
|
|
|
end
|
|
|
|
|
2005-10-12 22:47:39 +00:00
|
|
|
def test_cdata_section
|
|
|
|
assert_equal "<![CDATA[<hello world>]]>", cdata_section("<hello world>")
|
|
|
|
end
|
2010-08-14 05:13:00 +00:00
|
|
|
|
2013-10-29 17:17:57 +00:00
|
|
|
def test_cdata_section_with_string_conversion
|
|
|
|
assert_equal "<![CDATA[]]>", cdata_section(nil)
|
|
|
|
end
|
|
|
|
|
2012-04-30 13:08:06 +00:00
|
|
|
def test_cdata_section_splitted
|
|
|
|
assert_equal "<![CDATA[hello]]]]><![CDATA[>world]]>", cdata_section("hello]]>world")
|
|
|
|
assert_equal "<![CDATA[hello]]]]><![CDATA[>world]]]]><![CDATA[>again]]>", cdata_section("hello]]>world]]>again")
|
|
|
|
end
|
|
|
|
|
2006-10-18 16:42:19 +00:00
|
|
|
def test_escape_once
|
2016-08-06 16:50:17 +00:00
|
|
|
assert_equal "1 < 2 & 3", escape_once("1 < 2 & 3")
|
2013-01-28 22:26:12 +00:00
|
|
|
assert_equal " ' ' λ λ " ' < > ", escape_once(" ' ' λ λ \" ' < > ")
|
2006-10-18 16:42:19 +00:00
|
|
|
end
|
2010-08-14 05:13:00 +00:00
|
|
|
|
2010-06-29 22:12:48 +00:00
|
|
|
def test_tag_honors_html_safe_for_param_values
|
2016-08-06 16:50:17 +00:00
|
|
|
["1&2", "1 < 2", "“test“"].each do |escaped|
|
2016-08-06 17:36:34 +00:00
|
|
|
assert_equal %(<a href="#{escaped}" />), tag("a", href: escaped.html_safe)
|
2016-06-27 17:00:54 +00:00
|
|
|
assert_equal %(<a href="#{escaped}"></a>), tag.a(href: escaped.html_safe)
|
2006-10-18 15:58:07 +00:00
|
|
|
end
|
|
|
|
end
|
2010-08-14 05:13:00 +00:00
|
|
|
|
2014-06-11 00:33:34 +00:00
|
|
|
def test_tag_honors_html_safe_with_escaped_array_class
|
2016-08-06 17:36:34 +00:00
|
|
|
assert_equal '<p class="song> play>" />', tag("p", class: ["song>", raw("play>")])
|
|
|
|
assert_equal '<p class="song> play>" />', tag("p", class: [raw("song>"), "play>"])
|
2016-06-27 17:00:54 +00:00
|
|
|
end
|
2014-06-11 00:33:34 +00:00
|
|
|
|
2016-06-27 17:00:54 +00:00
|
|
|
def test_tag_builder_honors_html_safe_with_escaped_array_class
|
2016-08-06 16:50:17 +00:00
|
|
|
assert_equal '<p class="song> play>"></p>', tag.p(class: ["song>", raw("play>")])
|
|
|
|
assert_equal '<p class="song> play>"></p>', tag.p(class: [raw("song>"), "play>"])
|
2014-06-11 00:33:34 +00:00
|
|
|
end
|
|
|
|
|
2016-07-28 23:12:21 +00:00
|
|
|
def test_tag_does_not_honor_html_safe_double_quotes_as_attributes
|
|
|
|
assert_dom_equal '<p title=""">content</p>',
|
2016-09-01 21:41:49 +00:00
|
|
|
content_tag("p", "content", title: '"'.html_safe)
|
2016-07-28 23:12:21 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_data_tag_does_not_honor_html_safe_double_quotes_as_attributes
|
|
|
|
assert_dom_equal '<p data-title=""">content</p>',
|
2016-09-01 21:41:49 +00:00
|
|
|
content_tag("p", "content", data: { title: '"'.html_safe })
|
2016-07-28 23:12:21 +00:00
|
|
|
end
|
|
|
|
|
2006-10-18 15:58:07 +00:00
|
|
|
def test_skip_invalid_escaped_attributes
|
2016-08-06 16:50:17 +00:00
|
|
|
["&1;", "dfa3;", "& #123;"].each do |escaped|
|
2016-08-06 17:36:34 +00:00
|
|
|
assert_equal %(<a href="#{escaped.gsub(/&/, '&')}" />), tag("a", href: escaped)
|
2016-06-27 17:00:54 +00:00
|
|
|
assert_equal %(<a href="#{escaped.gsub(/&/, '&')}"></a>), tag.a(href: escaped)
|
2006-10-18 15:58:07 +00:00
|
|
|
end
|
|
|
|
end
|
2007-09-24 08:13:55 +00:00
|
|
|
|
|
|
|
def test_disable_escaping
|
2016-08-06 17:36:34 +00:00
|
|
|
assert_equal '<a href="&" />', tag("a", { href: "&" }, false, false)
|
2007-09-24 08:13:55 +00:00
|
|
|
end
|
2010-10-17 13:18:25 +00:00
|
|
|
|
2016-06-27 17:00:54 +00:00
|
|
|
def test_tag_builder_disable_escaping
|
2016-08-06 16:50:17 +00:00
|
|
|
assert_equal '<a href="&"></a>', tag.a(href: "&", escape_attributes: false)
|
2016-08-16 07:30:11 +00:00
|
|
|
assert_equal '<a href="&">cnt</a>', tag.a(href: "&" , escape_attributes: false) { "cnt" }
|
2016-08-06 16:50:17 +00:00
|
|
|
assert_equal '<br data-hidden="&">', tag.br("data-hidden": "&" , escape_attributes: false)
|
|
|
|
assert_equal '<a href="&">content</a>', tag.a("content", href: "&", escape_attributes: false)
|
2016-08-16 07:30:11 +00:00
|
|
|
assert_equal '<a href="&">content</a>', tag.a(href: "&", escape_attributes: false) { "content" }
|
2016-06-27 17:00:54 +00:00
|
|
|
end
|
|
|
|
|
2010-10-17 13:18:25 +00:00
|
|
|
def test_data_attributes
|
2016-08-06 16:50:17 +00:00
|
|
|
["data", :data].each { |data|
|
2012-11-01 10:49:47 +00:00
|
|
|
assert_dom_equal '<a data-a-float="3.14" data-a-big-decimal="-123.456" data-a-number="1" data-array="[1,2,3]" data-hash="{"key":"value"}" data-string-with-quotes="double"quote"party"" data-string="hello" data-symbol="foo" />',
|
2016-08-16 07:30:11 +00:00
|
|
|
tag("a", data => { a_float: 3.14, a_big_decimal: BigDecimal.new("-123.456"), a_number: 1, string: "hello", symbol: :foo, array: [1, 2, 3], hash: { key: "value" }, string_with_quotes: 'double"quote"party"' })
|
2016-06-27 17:00:54 +00:00
|
|
|
assert_dom_equal '<a data-a-float="3.14" data-a-big-decimal="-123.456" data-a-number="1" data-array="[1,2,3]" data-hash="{"key":"value"}" data-string-with-quotes="double"quote"party"" data-string="hello" data-symbol="foo" />',
|
2016-08-16 07:30:11 +00:00
|
|
|
tag.a(data: { a_float: 3.14, a_big_decimal: BigDecimal.new("-123.456"), a_number: 1, string: "hello", symbol: :foo, array: [1, 2, 3], hash: { key: "value" }, string_with_quotes: 'double"quote"party"' })
|
2010-10-17 13:18:25 +00:00
|
|
|
}
|
|
|
|
end
|
2014-09-03 20:03:58 +00:00
|
|
|
|
|
|
|
def test_aria_attributes
|
2016-08-06 16:50:17 +00:00
|
|
|
["aria", :aria].each { |aria|
|
2014-09-03 20:03:58 +00:00
|
|
|
assert_dom_equal '<a aria-a-float="3.14" aria-a-big-decimal="-123.456" aria-a-number="1" aria-array="[1,2,3]" aria-hash="{"key":"value"}" aria-string-with-quotes="double"quote"party"" aria-string="hello" aria-symbol="foo" />',
|
2016-08-16 07:30:11 +00:00
|
|
|
tag("a", aria => { a_float: 3.14, a_big_decimal: BigDecimal.new("-123.456"), a_number: 1, string: "hello", symbol: :foo, array: [1, 2, 3], hash: { key: "value" }, string_with_quotes: 'double"quote"party"' })
|
2016-06-27 17:00:54 +00:00
|
|
|
assert_dom_equal '<a aria-a-float="3.14" aria-a-big-decimal="-123.456" aria-a-number="1" aria-array="[1,2,3]" aria-hash="{"key":"value"}" aria-string-with-quotes="double"quote"party"" aria-string="hello" aria-symbol="foo" />',
|
2016-08-16 07:30:11 +00:00
|
|
|
tag.a(aria: { a_float: 3.14, a_big_decimal: BigDecimal.new("-123.456"), a_number: 1, string: "hello", symbol: :foo, array: [1, 2, 3], hash: { key: "value" }, string_with_quotes: 'double"quote"party"' })
|
2014-09-03 20:03:58 +00:00
|
|
|
}
|
|
|
|
end
|
2016-02-12 22:06:59 +00:00
|
|
|
|
|
|
|
def test_link_to_data_nil_equal
|
2016-08-06 17:44:11 +00:00
|
|
|
div_type1 = content_tag(:div, "test", "data-tooltip" => nil)
|
2016-08-16 07:30:11 +00:00
|
|
|
div_type2 = content_tag(:div, "test", data: { tooltip: nil })
|
2016-08-06 17:55:02 +00:00
|
|
|
assert_dom_equal div_type1, div_type2
|
2016-02-12 22:06:59 +00:00
|
|
|
end
|
2016-06-27 17:00:54 +00:00
|
|
|
|
|
|
|
def test_tag_builder_link_to_data_nil_equal
|
2016-08-06 17:44:11 +00:00
|
|
|
div_type1 = tag.div "test", 'data-tooltip': nil
|
2016-08-16 07:30:11 +00:00
|
|
|
div_type2 = tag.div "test", data: { tooltip: nil }
|
2016-06-27 17:00:54 +00:00
|
|
|
assert_dom_equal div_type1, div_type2
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_tag_builder_allow_call_via_method_object
|
|
|
|
assert_equal "<foo></foo>", tag.method(:foo).call
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_tag_builder_dasherize_names
|
|
|
|
assert_equal "<img-slider></img-slider>", tag.img_slider
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_respond_to
|
|
|
|
assert_respond_to tag, :any_tag
|
|
|
|
end
|
2005-03-06 11:50:41 +00:00
|
|
|
end
|