diff --git a/app/controllers/wiki_controller.rb b/app/controllers/wiki_controller.rb index 95667bae..d98bb7f7 100644 --- a/app/controllers/wiki_controller.rb +++ b/app/controllers/wiki_controller.rb @@ -392,7 +392,8 @@ class WikiController < ApplicationController def truncate(text, length = 30, truncate_string = '...') return text if text.length <= length len = length - truncate_string.length - text.split.inject('') do |t, word| + t = '' + text.split.collect do | word| if t.length + word.length <= len t << word + ' ' else diff --git a/test/functional/wiki_controller_test.rb b/test/functional/wiki_controller_test.rb index 30517f77..b16ce0fc 100644 --- a/test/functional/wiki_controller_test.rb +++ b/test/functional/wiki_controller_test.rb @@ -38,9 +38,9 @@ class WikiControllerTest < ActionController::TestCase def test_truncate_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 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 def test_authenticate @@ -323,6 +323,16 @@ class WikiControllerTest < ActionController::TestCase 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 set_web_property :published, true