aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/template/text_helper_test.rb
diff options
context:
space:
mode:
authorGuirec Corbel <guirec.corbel@gmail.com>2012-07-28 17:34:36 -0400
committerGCorbel <guirec.corbel@gmail.com>2012-09-08 07:24:17 -0400
commit963c50eca87373bed403358c076b377ad62454ef (patch)
tree7a1d91408fdc3435b8a164250d6bfb4b4e5031c0 /actionpack/test/template/text_helper_test.rb
parentf415475621c79cbc2d93e1ecf10805a4100a5d43 (diff)
downloadrails-963c50eca87373bed403358c076b377ad62454ef.tar.gz
rails-963c50eca87373bed403358c076b377ad62454ef.tar.bz2
rails-963c50eca87373bed403358c076b377ad62454ef.zip
Add a separation option for the excerpt function
The separation option enable to keep entire words, lines or anything. To split by line, like github, we can set the separation option as \n. To split by word, like google, we can set the separation option as " ". The radius option represent the number of lines or words we want to have in the result. The default behaviour is the same. If we don't set the separation option, it split the text any where.
Diffstat (limited to 'actionpack/test/template/text_helper_test.rb')
-rw-r--r--actionpack/test/template/text_helper_test.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/actionpack/test/template/text_helper_test.rb b/actionpack/test/template/text_helper_test.rb
index c0f694b2bf..4525efe73c 100644
--- a/actionpack/test/template/text_helper_test.rb
+++ b/actionpack/test/template/text_helper_test.rb
@@ -303,6 +303,19 @@ class TextHelperTest < ActionView::TestCase
assert_equal options, passed_options
end
+ def test_excerpt_with_separator
+ options = { :separator => ' ', :radius => 1 }
+ assert_equal('...a very beautiful...', excerpt('This is a very beautiful morning', 'very', options))
+ assert_equal('This is...', excerpt('This is a very beautiful morning', 'this', options))
+ assert_equal('...beautiful morning', excerpt('This is a very beautiful morning', 'morning', options))
+
+ options = { :separator => "\n", :radius => 0 }
+ assert_equal("...very long...", excerpt("my very\nvery\nvery long\nstring", 'long', options))
+
+ options = { :separator => "\n", :radius => 1 }
+ assert_equal("...very\nvery long\nstring", excerpt("my very\nvery\nvery long\nstring", 'long', options))
+ end
+
def test_word_wrap
assert_equal("my very very\nvery long\nstring", word_wrap("my very very very long string", :line_width => 15))
end