aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/template/url_helper_test.rb
diff options
context:
space:
mode:
authorCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-05-31 09:18:14 -0300
committerCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2012-05-31 09:44:10 -0300
commite2f5f01675f3c575e820532ab7cce6fe068ecb28 (patch)
tree22cd78c27df5e8b9728b6bd153cb321d3ea509b7 /actionpack/test/template/url_helper_test.rb
parentb6eb22cb6490e4c8d0b19541703b0322968c5a1c (diff)
downloadrails-e2f5f01675f3c575e820532ab7cce6fe068ecb28.tar.gz
rails-e2f5f01675f3c575e820532ab7cce6fe068ecb28.tar.bz2
rails-e2f5f01675f3c575e820532ab7cce6fe068ecb28.zip
Simplify link_to using content_tag
Add some tests for link_to with blocks and escaping content.
Diffstat (limited to 'actionpack/test/template/url_helper_test.rb')
-rw-r--r--actionpack/test/template/url_helper_test.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb
index 365a86ab91..62608a727f 100644
--- a/actionpack/test/template/url_helper_test.rb
+++ b/actionpack/test/template/url_helper_test.rb
@@ -277,6 +277,16 @@ class UrlHelperTest < ActiveSupport::TestCase
)
end
+ def test_link_tag_with_block
+ assert_dom_equal '<a href="/"><span>Example site</span></a>',
+ link_to('/') { content_tag(:span, 'Example site') }
+ end
+
+ def test_link_tag_with_block_and_html_options
+ assert_dom_equal '<a class="special" href="/"><span>Example site</span></a>',
+ link_to('/', :class => "special") { content_tag(:span, 'Example site') }
+ end
+
def test_link_tag_using_block_in_erb
out = render_erb %{<%= link_to('/') do %>Example site<% end %>}
assert_equal '<a href="/">Example site</a>', out
@@ -289,6 +299,16 @@ class UrlHelperTest < ActiveSupport::TestCase
)
end
+ def test_link_tag_escapes_content
+ assert_dom_equal '<a href="/">Malicious &lt;script&gt;content&lt;/script&gt;</a>',
+ link_to("Malicious <script>content</script>", "/")
+ end
+
+ def test_link_tag_does_not_escape_html_safe_content
+ assert_dom_equal '<a href="/">Malicious <script>content</script></a>',
+ link_to("Malicious <script>content</script>".html_safe, "/")
+ end
+
def test_link_to_unless
assert_equal "Showing", link_to_unless(true, "Showing", url_hash)