aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorJeremy Kemper <jeremy@bitsweat.net>2007-12-21 11:51:17 +0000
committerJeremy Kemper <jeremy@bitsweat.net>2007-12-21 11:51:17 +0000
commita4c77f9bc4008bfead6c9edb3b951a3faf5acc39 (patch)
tree793c5850a73cb01b1698f0fcef9358c26acb2fad /actionpack
parent8931a6ec16db78cf7ad8ffd0ca1ebec1694f9700 (diff)
downloadrails-a4c77f9bc4008bfead6c9edb3b951a3faf5acc39.tar.gz
rails-a4c77f9bc4008bfead6c9edb3b951a3faf5acc39.tar.bz2
rails-a4c77f9bc4008bfead6c9edb3b951a3faf5acc39.zip
Ruby 1.9 compat: text helper
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@8464 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/test/template/text_helper_test.rb45
-rw-r--r--actionpack/test/template/url_helper_test.rb2
-rw-r--r--actionpack/test/testing_sandbox.rb12
3 files changed, 40 insertions, 19 deletions
diff --git a/actionpack/test/template/text_helper_test.rb b/actionpack/test/template/text_helper_test.rb
index 92d6bc3ae2..6bfe18123b 100644
--- a/actionpack/test/template/text_helper_test.rb
+++ b/actionpack/test/template/text_helper_test.rb
@@ -1,5 +1,5 @@
-require "#{File.dirname(__FILE__)}/../abstract_unit"
-require "#{File.dirname(__FILE__)}/../testing_sandbox"
+require 'abstract_unit'
+require 'testing_sandbox'
class TextHelperTest < Test::Unit::TestCase
include ActionView::Helpers::TextHelper
@@ -36,16 +36,26 @@ class TextHelperTest < Test::Unit::TestCase
assert_equal str[0...27] + "...", truncate(str)
end
- def test_truncate_multibyte
- with_kcode 'none' do
- assert_equal "\354\225\210\353\205\225\355...", truncate("\354\225\210\353\205\225\355\225\230\354\204\270\354\232\224", 10)
+ if RUBY_VERSION < '1.9.0'
+ def test_truncate_multibyte
+ with_kcode 'none' do
+ assert_equal "\354\225\210\353\205\225\355...", truncate("\354\225\210\353\205\225\355\225\230\354\204\270\354\232\224", 10)
+ end
+ with_kcode 'u' do
+ assert_equal "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 ...",
+ truncate("\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", 10)
+ end
end
- with_kcode 'u' do
- assert_equal "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 ...",
- truncate("\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", 10)
+ else
+ def test_truncate_multibyte
+ assert_equal "\354\225\210\353\205\225\355...",
+ truncate("\354\225\210\353\205\225\355\225\230\354\204\270\354\232\224", 10)
+
+ assert_equal "\354\225\204\353\246\254\353\236\221 \354\225\204\353\246\254 ...".force_encoding('UTF-8'),
+ truncate("\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('UTF-8'), 10)
end
end
-
+
def test_highlighter
assert_equal(
"This is a <strong class=\"highlight\">beautiful</strong> morning",
@@ -103,15 +113,22 @@ class TextHelperTest < Test::Unit::TestCase
assert_equal('...is a beautiful? morn...', excerpt('This is a beautiful? morning', 'beautiful', 5))
end
- def test_excerpt_with_utf8
- with_kcode('u') do
- assert_equal("...fficiency could not be h...", excerpt("That's why efficiency could not be helped", 'could', 8))
+ if RUBY_VERSION < '1.9'
+ def test_excerpt_with_utf8
+ with_kcode('u') do
+ assert_equal("...fficiency could not be h...", excerpt("That's why efficiency could not be helped", 'could', 8))
+ end
+ with_kcode('none') do
+ assert_equal("...\203ciency could not be h...", excerpt("That's why efficiency could not be helped", 'could', 8))
+ end
end
- with_kcode('none') do
+ else
+ def test_excerpt_with_utf8
+ assert_equal("...fficiency could not be h...".force_encoding('UTF-8'), excerpt("That's why efficiency could not be helped".force_encoding('UTF-8'), 'could', 8))
assert_equal("...\203ciency could not be h...", excerpt("That's why efficiency could not be helped", 'could', 8))
end
end
-
+
def test_word_wrap
assert_equal("my very very\nvery long\nstring", word_wrap("my very very very long string", 15))
end
diff --git a/actionpack/test/template/url_helper_test.rb b/actionpack/test/template/url_helper_test.rb
index ee75965be9..9cd3b6e2f9 100644
--- a/actionpack/test/template/url_helper_test.rb
+++ b/actionpack/test/template/url_helper_test.rb
@@ -1,4 +1,4 @@
-require "#{File.dirname(__FILE__)}/../abstract_unit"
+require 'abstract_unit'
RequestMock = Struct.new("Request", :request_uri, :protocol, :host_with_port, :env)
diff --git a/actionpack/test/testing_sandbox.rb b/actionpack/test/testing_sandbox.rb
index b3b8b0f4d4..c36585104f 100644
--- a/actionpack/test/testing_sandbox.rb
+++ b/actionpack/test/testing_sandbox.rb
@@ -1,11 +1,15 @@
module TestingSandbox
# Temporarily replaces KCODE for the block
def with_kcode(kcode)
- old_kcode, $KCODE = $KCODE, kcode
- begin
+ if RUBY_VERSION < '1.9'
+ old_kcode, $KCODE = $KCODE, kcode
+ begin
+ yield
+ ensure
+ $KCODE = old_kcode
+ end
+ else
yield
- ensure
- $KCODE = old_kcode
end
end
end