diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-05-26 14:11:28 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2012-05-26 14:27:07 -0300 |
commit | 2c2b0beaf46c997773b9adc8ef9ff57547a770a3 (patch) | |
tree | 70ebb473ba6a05b7bbe1fe9e2e193671f443facf /actionpack/test/template/text_helper_test.rb | |
parent | eedc513503785490a7caed23cd0a0aef3536759f (diff) | |
download | rails-2c2b0beaf46c997773b9adc8ef9ff57547a770a3.tar.gz rails-2c2b0beaf46c997773b9adc8ef9ff57547a770a3.tar.bz2 rails-2c2b0beaf46c997773b9adc8ef9ff57547a770a3.zip |
Add `:escape` option for `truncate`
This options can be used to not escape the result by default.
Diffstat (limited to 'actionpack/test/template/text_helper_test.rb')
-rw-r--r-- | actionpack/test/template/text_helper_test.rb | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/actionpack/test/template/text_helper_test.rb b/actionpack/test/template/text_helper_test.rb index 4b1c1ef78b..a3ab091c6c 100644 --- a/actionpack/test/template/text_helper_test.rb +++ b/actionpack/test/template/text_helper_test.rb @@ -119,6 +119,15 @@ class TextHelperTest < ActionView::TestCase assert_equal "Hello <sc...", truncate("Hello <script>code!</script>World!!", :length => 12) end + def test_truncate_should_not_escape_the_input_with_escape_false + assert_equal "Hello <sc...", truncate("Hello <script>code!</script>World!!", :length => 12, :escape => false) + end + + def test_truncate_with_escape_false_should_be_html_safe + truncated = truncate("Hello <script>code!</script>World!!", :length => 12, :escape => false) + assert truncated.html_safe? + end + def test_truncate_with_block_should_be_html_safe truncated = truncate("Here's a long test and I need a continue to read link", :length => 27) { link_to 'Continue', '#' } assert truncated.html_safe? @@ -129,6 +138,16 @@ class TextHelperTest < ActionView::TestCase truncate("<script>code!</script>Here's a long test and I need a continue to read link", :length => 27) { link_to 'Continue', '#' } end + def test_truncate_with_block_should_not_escape_the_input_with_escape_false + assert_equal "<script>code!</script>He...<a href=\"#\">Continue</a>", + truncate("<script>code!</script>Here's a long test and I need a continue to read link", :length => 27, :escape => false) { link_to 'Continue', '#' } + end + + def test_truncate_with_block_with_escape_false_should_be_html_safe + truncated = truncate("<script>code!</script>Here's a long test and I need a continue to read link", :length => 27, :escape => false) { link_to 'Continue', '#' } + assert truncated.html_safe? + end + def test_truncate_with_block_should_escape_the_block assert_equal "Here's a long test and I...<script>alert('foo');</script>", truncate("Here's a long test and I need a continue to read link", :length => 27) { "<script>alert('foo');</script>" } |