diff options
author | root <mohamed.o.alnagdy@gmail.com> | 2014-07-16 19:48:07 +0200 |
---|---|---|
committer | root <mohamed.o.alnagdy@gmail.com> | 2014-07-16 19:48:07 +0200 |
commit | a9d3b77e494608cedcdad86d7e0c8a07694ffea5 (patch) | |
tree | f6800b11d589dd9752721b62fefa87b1d1d6aaee /activesupport/test/core_ext | |
parent | 002cf5fac4d71e77805c0e1dad3b9499b1f551ca (diff) | |
download | rails-a9d3b77e494608cedcdad86d7e0c8a07694ffea5.tar.gz rails-a9d3b77e494608cedcdad86d7e0c8a07694ffea5.tar.bz2 rails-a9d3b77e494608cedcdad86d7e0c8a07694ffea5.zip |
Added truncate_words method to activesupport strings
Diffstat (limited to 'activesupport/test/core_ext')
-rw-r--r-- | activesupport/test/core_ext/string_ext_test.rb | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/string_ext_test.rb b/activesupport/test/core_ext/string_ext_test.rb index 515144245a..7c4089eb73 100644 --- a/activesupport/test/core_ext/string_ext_test.rb +++ b/activesupport/test/core_ext/string_ext_test.rb @@ -229,6 +229,26 @@ class StringInflectionsTest < ActiveSupport::TestCase assert_equal "Hello Big[...]", "Hello Big World!".truncate(15, :omission => "[...]", :separator => /\s/) end + def test_truncate_words + assert_equal "Hello Big World!", "Hello Big World!".truncate_words(3) + assert_equal "Hello Big...", "Hello Big World!".truncate_words(2) + end + + def test_truncate_words_with_ommission + assert_equal "Hello Big World!", "Hello Big World!".truncate_words(3, :omission => "[...]") + assert_equal "Hello Big[...]", "Hello Big World!".truncate_words(2, :omission => "[...]") + end + + def test_truncate_words_with_separator + assert_equal "Hello<br>Big<br>World!...", "Hello<br>Big<br>World!<br>".truncate_words(3, :separator => '<br>') + assert_equal "Hello<br>Big<br>World!", "Hello<br>Big<br>World!".truncate_words(3, :separator => '<br>') + end + + def test_truncate_words_with_separator_and_ommission + assert_equal "Hello<br>Big<br>World![...]", "Hello<br>Big<br>World!<br>".truncate_words(3, :omission => "[...]", :separator => '<br>') + assert_equal "Hello<br>Big<br>World!", "Hello<br>Big<br>World!".truncate_words(3, :omission => "[...]", :separator => '<br>') + end + def test_truncate_multibyte assert_equal "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 ...".force_encoding(Encoding::UTF_8), "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 \354\225\204\353\235\274\353\246\254\354\230\244".force_encoding(Encoding::UTF_8).truncate(10) |