aboutsummaryrefslogtreecommitdiffstats
path: root/actionview/test/template/text_helper_test.rb
diff options
context:
space:
mode:
authorLucas Mazza <lucastmazza@gmail.com>2014-06-19 14:58:36 -0300
committerLucas Mazza <lucastmazza@gmail.com>2014-06-19 15:22:23 -0300
commit9f27e1076ac6aacb33b0f4ee0e940c2a90f1c630 (patch)
tree9b0b6c8cb68a524de923aaa974b6da4e580b4b06 /actionview/test/template/text_helper_test.rb
parent490f25034d62817f9315084ddc0506ff6bc65055 (diff)
downloadrails-9f27e1076ac6aacb33b0f4ee0e940c2a90f1c630.tar.gz
rails-9f27e1076ac6aacb33b0f4ee0e940c2a90f1c630.tar.bz2
rails-9f27e1076ac6aacb33b0f4ee0e940c2a90f1c630.zip
'TextHelper#highlight' now accepts a block to highlight the matched words.
The helper will yield each matched word, and you can use this instead of the ':highlighter' option for more complex replacing logic: highlight('My email is me@work.com', EMAIL_REGEXP) { |m| mail_to(m) } # => 'My email is <a href="mailto:me@work.com">me@work.com</a>'
Diffstat (limited to 'actionview/test/template/text_helper_test.rb')
-rw-r--r--actionview/test/template/text_helper_test.rb7
1 files changed, 7 insertions, 0 deletions
diff --git a/actionview/test/template/text_helper_test.rb b/actionview/test/template/text_helper_test.rb
index 2467c9527a..858232a2b9 100644
--- a/actionview/test/template/text_helper_test.rb
+++ b/actionview/test/template/text_helper_test.rb
@@ -265,6 +265,13 @@ class TextHelperTest < ActionView::TestCase
assert_equal options, passed_options
end
+ def test_highlight_with_block
+ assert_equal(
+ "<b>one</b> <b>two</b> <b>three</b>",
+ highlight("one two three", ["one", "two", "three"]) { |word| "<b>#{word}</b>" }
+ )
+ end
+
def test_excerpt
assert_equal("...is a beautiful morn...", excerpt("This is a beautiful morning", "beautiful", :radius => 5))
assert_equal("This is a...", excerpt("This is a beautiful morning", "this", :radius => 5))