Array#collect is faster than Array#inject
Also add some more tests.
This commit is contained in:
parent
282515d907
commit
1613973929
|
@ -392,7 +392,8 @@ class WikiController < ApplicationController
|
||||||
def truncate(text, length = 30, truncate_string = '...')
|
def truncate(text, length = 30, truncate_string = '...')
|
||||||
return text if text.length <= length
|
return text if text.length <= length
|
||||||
len = length - truncate_string.length
|
len = length - truncate_string.length
|
||||||
text.split.inject('') do |t, word|
|
t = ''
|
||||||
|
text.split.collect do | word|
|
||||||
if t.length + word.length <= len
|
if t.length + word.length <= len
|
||||||
t << word + ' '
|
t << word + ' '
|
||||||
else
|
else
|
||||||
|
|
|
@ -38,9 +38,9 @@ class WikiControllerTest < ActionController::TestCase
|
||||||
|
|
||||||
def test_truncate_page_name
|
def test_truncate_page_name
|
||||||
wanted_page_name = 'This is a very, very, very, very, VERY long page name'
|
wanted_page_name = 'This is a very, very, very, very, VERY long page name'
|
||||||
evil_page_name = 'This page name has lots of fun & games'
|
evil_page_name = 'This page has plenty of fun & games'
|
||||||
assert_equal 'This is a very, very, very,...', @controller.truncate(WikiWords.separate(wanted_page_name), 35)
|
assert_equal 'This is a very, very, very,...', @controller.truncate(WikiWords.separate(wanted_page_name), 35)
|
||||||
assert_equal 'This page name has lots of...', @controller.truncate(WikiWords.separate(evil_page_name))
|
assert_equal 'This page has plenty of fun...', @controller.truncate(WikiWords.separate(evil_page_name))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_authenticate
|
def test_authenticate
|
||||||
|
@ -323,6 +323,16 @@ class WikiControllerTest < ActionController::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
def test_source
|
||||||
|
r = process('source', 'web' => 'wiki1', 'id' => 'HomePage')
|
||||||
|
|
||||||
|
assert_response(:success)
|
||||||
|
assert_match Regexp.new(Regexp.escape(%{HisWay would be MyWay $\\sin(x)\\begin{svg}&} +
|
||||||
|
%{lt;svg/>\\end{svg}\\includegraphics\[width=3em\]{foo}$ in kinda} +
|
||||||
|
%{ ThatWay in HisWay though MyWay \\OverThere -- see SmartEngine in t} +
|
||||||
|
%{hat SmartEngineGUI})), r.body
|
||||||
|
end
|
||||||
|
|
||||||
def test_published
|
def test_published
|
||||||
set_web_property :published, true
|
set_web_property :published, true
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue