diff options
author | Sergey Nartimov <just.lest@gmail.com> | 2011-12-25 14:34:58 +0300 |
---|---|---|
committer | Sergey Nartimov <just.lest@gmail.com> | 2011-12-25 14:34:58 +0300 |
commit | 1e9e88fcd335c7d5a99159d592c3e1b605510a16 (patch) | |
tree | d4ccf417d4ed7c999b574ba941cf9ecb68f7882c /activesupport/test | |
parent | 4c1701c0ca6ae77a8274f59460751d1b1d83ce1b (diff) | |
download | rails-1e9e88fcd335c7d5a99159d592c3e1b605510a16.tar.gz rails-1e9e88fcd335c7d5a99159d592c3e1b605510a16.tar.bz2 rails-1e9e88fcd335c7d5a99159d592c3e1b605510a16.zip |
remove checks for encodings availability
Diffstat (limited to 'activesupport/test')
-rw-r--r-- | activesupport/test/buffered_logger_test.rb | 12 | ||||
-rw-r--r-- | activesupport/test/caching_test.rb | 40 | ||||
-rw-r--r-- | activesupport/test/json/encoding_test.rb | 4 | ||||
-rw-r--r-- | activesupport/test/multibyte_test_helpers.rb | 5 |
4 files changed, 25 insertions, 36 deletions
diff --git a/activesupport/test/buffered_logger_test.rb b/activesupport/test/buffered_logger_test.rb index 1540e8df9b..b9891c74c8 100644 --- a/activesupport/test/buffered_logger_test.rb +++ b/activesupport/test/buffered_logger_test.rb @@ -32,9 +32,7 @@ class BufferedLoggerTest < Test::Unit::TestCase logger.level = Logger::DEBUG str = "\x80" - if str.respond_to?(:force_encoding) - str.force_encoding("ASCII-8BIT") - end + str.force_encoding("ASCII-8BIT") logger.add Logger::DEBUG, str ensure @@ -52,9 +50,7 @@ class BufferedLoggerTest < Test::Unit::TestCase logger.level = Logger::DEBUG str = "\x80" - if str.respond_to?(:force_encoding) - str.force_encoding("ASCII-8BIT") - end + str.force_encoding("ASCII-8BIT") logger.add Logger::DEBUG, str ensure @@ -124,9 +120,7 @@ class BufferedLoggerTest < Test::Unit::TestCase @logger.info(BYTE_STRING) assert @output.string.include?(UNICODE_STRING) byte_string = @output.string.dup - if byte_string.respond_to?(:force_encoding) - byte_string.force_encoding("ASCII-8BIT") - end + byte_string.force_encoding("ASCII-8BIT") assert byte_string.include?(BYTE_STRING) end end diff --git a/activesupport/test/caching_test.rb b/activesupport/test/caching_test.rb index 5488070d8c..aa6fb14e7b 100644 --- a/activesupport/test/caching_test.rb +++ b/activesupport/test/caching_test.rb @@ -398,22 +398,9 @@ end # The error is caused by charcter encodings that can't be compared with ASCII-8BIT regular expressions and by special # characters like the umlaut in UTF-8. module EncodedKeyCacheBehavior - if defined?(Encoding) - Encoding.list.each do |encoding| - define_method "test_#{encoding.name.underscore}_encoded_values" do - key = "foo".force_encoding(encoding) - assert @cache.write(key, "1", :raw => true) - assert_equal "1", @cache.read(key) - assert_equal "1", @cache.fetch(key) - assert @cache.delete(key) - assert_equal "2", @cache.fetch(key, :raw => true) { "2" } - assert_equal 3, @cache.increment(key) - assert_equal 2, @cache.decrement(key) - end - end - - def test_common_utf8_values - key = "\xC3\xBCmlaut".force_encoding(Encoding::UTF_8) + Encoding.list.each do |encoding| + define_method "test_#{encoding.name.underscore}_encoded_values" do + key = "foo".force_encoding(encoding) assert @cache.write(key, "1", :raw => true) assert_equal "1", @cache.read(key) assert_equal "1", @cache.fetch(key) @@ -422,12 +409,23 @@ module EncodedKeyCacheBehavior assert_equal 3, @cache.increment(key) assert_equal 2, @cache.decrement(key) end + end - def test_retains_encoding - key = "\xC3\xBCmlaut".force_encoding(Encoding::UTF_8) - assert @cache.write(key, "1", :raw => true) - assert_equal Encoding::UTF_8, key.encoding - end + def test_common_utf8_values + key = "\xC3\xBCmlaut".force_encoding(Encoding::UTF_8) + assert @cache.write(key, "1", :raw => true) + assert_equal "1", @cache.read(key) + assert_equal "1", @cache.fetch(key) + assert @cache.delete(key) + assert_equal "2", @cache.fetch(key, :raw => true) { "2" } + assert_equal 3, @cache.increment(key) + assert_equal 2, @cache.decrement(key) + end + + def test_retains_encoding + key = "\xC3\xBCmlaut".force_encoding(Encoding::UTF_8) + assert @cache.write(key, "1", :raw => true) + assert_equal Encoding::UTF_8, key.encoding end end diff --git a/activesupport/test/json/encoding_test.rb b/activesupport/test/json/encoding_test.rb index ad9a497515..a6435a763a 100644 --- a/activesupport/test/json/encoding_test.rb +++ b/activesupport/test/json/encoding_test.rb @@ -91,11 +91,11 @@ class TestJSONEncoding < Test::Unit::TestCase def test_utf8_string_encoded_properly result = ActiveSupport::JSON.encode('€2.99') assert_equal '"\\u20ac2.99"', result - assert_equal(Encoding::UTF_8, result.encoding) if result.respond_to?(:encoding) + assert_equal(Encoding::UTF_8, result.encoding) result = ActiveSupport::JSON.encode('✎☺') assert_equal '"\\u270e\\u263a"', result - assert_equal(Encoding::UTF_8, result.encoding) if result.respond_to?(:encoding) + assert_equal(Encoding::UTF_8, result.encoding) end def test_non_utf8_string_transcodes diff --git a/activesupport/test/multibyte_test_helpers.rb b/activesupport/test/multibyte_test_helpers.rb index 8839b75601..fdbe2f4350 100644 --- a/activesupport/test/multibyte_test_helpers.rb +++ b/activesupport/test/multibyte_test_helpers.rb @@ -3,10 +3,7 @@ module MultibyteTestHelpers UNICODE_STRING = 'こにちわ' ASCII_STRING = 'ohayo' - BYTE_STRING = "\270\236\010\210\245" - if BYTE_STRING.respond_to?(:force_encoding) - BYTE_STRING.force_encoding("ASCII-8BIT") - end + BYTE_STRING = "\270\236\010\210\245".force_encoding("ASCII-8BIT") def chars(str) ActiveSupport::Multibyte::Chars.new(str) |