diff options
author | José Valim <jose.valim@gmail.com> | 2011-12-24 05:47:21 -0800 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2011-12-24 05:47:21 -0800 |
commit | f5b9aefb574bf3cf1d3779606e54bd0a0a73d2aa (patch) | |
tree | da7a9a4d9cd8ad05648bde5d283715d5feea4d81 /actionpack/test | |
parent | a5fa310f406e299a1ac54d1a227bde93b7ce282b (diff) | |
parent | 5ca86ac8f924b333a5a01a47cc07cbcf39c16e80 (diff) | |
download | rails-f5b9aefb574bf3cf1d3779606e54bd0a0a73d2aa.tar.gz rails-f5b9aefb574bf3cf1d3779606e54bd0a0a73d2aa.tar.bz2 rails-f5b9aefb574bf3cf1d3779606e54bd0a0a73d2aa.zip |
Merge pull request #4160 from lest/deprecate-encoding-aware
deprecate String#encoding_aware? and remove its usage
Diffstat (limited to 'actionpack/test')
-rw-r--r-- | actionpack/test/abstract_unit.rb | 13 | ||||
-rw-r--r-- | actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb | 2 | ||||
-rw-r--r-- | actionpack/test/dispatch/response_test.rb | 3 | ||||
-rw-r--r-- | actionpack/test/dispatch/uploaded_file_test.rb | 8 | ||||
-rw-r--r-- | actionpack/test/template/javascript_helper_test.rb | 6 | ||||
-rw-r--r-- | actionpack/test/template/template_test.rb | 98 |
6 files changed, 57 insertions, 73 deletions
diff --git a/actionpack/test/abstract_unit.rb b/actionpack/test/abstract_unit.rb index 40ca23a39d..63109d592a 100644 --- a/actionpack/test/abstract_unit.rb +++ b/actionpack/test/abstract_unit.rb @@ -14,14 +14,11 @@ ENV['TMPDIR'] = File.join(File.dirname(__FILE__), 'tmp') require 'active_support/core_ext/kernel/reporting' -require 'active_support/core_ext/string/encoding' -if "ruby".encoding_aware? - # These are the normal settings that will be set up by Railties - # TODO: Have these tests support other combinations of these values - silence_warnings do - Encoding.default_internal = "UTF-8" - Encoding.default_external = "UTF-8" - end +# These are the normal settings that will be set up by Railties +# TODO: Have these tests support other combinations of these values +silence_warnings do + Encoding.default_internal = "UTF-8" + Encoding.default_external = "UTF-8" end require 'test/unit' diff --git a/actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb b/actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb index 04a0fb6f34..05569561d2 100644 --- a/actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb +++ b/actionpack/test/dispatch/request/url_encoded_params_parsing_test.rb @@ -146,8 +146,6 @@ class UrlEncodedParamsParsingTest < ActionDispatch::IntegrationTest end def assert_utf8(object) - return unless "ruby".encoding_aware? - correct_encoding = Encoding.default_internal unless object.is_a?(Hash) diff --git a/actionpack/test/dispatch/response_test.rb b/actionpack/test/dispatch/response_test.rb index 9bdd5ecbc6..82d1200f8e 100644 --- a/actionpack/test/dispatch/response_test.rb +++ b/actionpack/test/dispatch/response_test.rb @@ -6,9 +6,6 @@ class ResponseTest < ActiveSupport::TestCase end def test_response_body_encoding - # FIXME: remove this conditional on Rails 4.0 - return unless "<3".encoding_aware? - body = ["hello".encode('utf-8')] response = ActionDispatch::Response.new 200, {}, body assert_equal Encoding::UTF_8, response.body.encoding diff --git a/actionpack/test/dispatch/uploaded_file_test.rb b/actionpack/test/dispatch/uploaded_file_test.rb index 7e4a1519fb..0b95291e18 100644 --- a/actionpack/test/dispatch/uploaded_file_test.rb +++ b/actionpack/test/dispatch/uploaded_file_test.rb @@ -13,11 +13,9 @@ module ActionDispatch assert_equal 'foo', uf.original_filename end - if "ruby".encoding_aware? - def test_filename_should_be_in_utf_8 - uf = Http::UploadedFile.new(:filename => 'foo', :tempfile => Object.new) - assert_equal "UTF-8", uf.original_filename.encoding.to_s - end + def test_filename_should_be_in_utf_8 + uf = Http::UploadedFile.new(:filename => 'foo', :tempfile => Object.new) + assert_equal "UTF-8", uf.original_filename.encoding.to_s end def test_content_type diff --git a/actionpack/test/template/javascript_helper_test.rb b/actionpack/test/template/javascript_helper_test.rb index 4b9c3c97b1..d98ffe8fa7 100644 --- a/actionpack/test/template/javascript_helper_test.rb +++ b/actionpack/test/template/javascript_helper_test.rb @@ -28,11 +28,7 @@ class JavaScriptHelperTest < ActionView::TestCase assert_equal %(This \\"thing\\" is really\\n netos\\'), escape_javascript(%(This "thing" is really\n netos')) assert_equal %(backslash\\\\test), escape_javascript( %(backslash\\test) ) assert_equal %(dont <\\/close> tags), escape_javascript(%(dont </close> tags)) - if "ruby".encoding_aware? - assert_equal %(unicode 
 newline), escape_javascript(%(unicode \342\200\250 newline).force_encoding('UTF-8').encode!) - else - assert_equal %(unicode 
 newline), escape_javascript(%(unicode \342\200\250 newline)) - end + assert_equal %(unicode 
 newline), escape_javascript(%(unicode \342\200\250 newline).force_encoding('UTF-8').encode!) assert_equal %(dont <\\/close> tags), j(%(dont </close> tags)) end diff --git a/actionpack/test/template/template_test.rb b/actionpack/test/template/template_test.rb index 13d30a93ce..f9c228f0c3 100644 --- a/actionpack/test/template/template_test.rb +++ b/actionpack/test/template/template_test.rb @@ -114,67 +114,65 @@ class TestERBTemplate < ActiveSupport::TestCase end end - if "ruby".encoding_aware? - def test_resulting_string_is_utf8 - @template = new_template - assert_equal Encoding::UTF_8, render.encoding - end + def test_resulting_string_is_utf8 + @template = new_template + assert_equal Encoding::UTF_8, render.encoding + end + + def test_no_magic_comment_word_with_utf_8 + @template = new_template("hello \u{fc}mlat") + assert_equal Encoding::UTF_8, render.encoding + assert_equal "hello \u{fc}mlat", render + end - def test_no_magic_comment_word_with_utf_8 - @template = new_template("hello \u{fc}mlat") + # This test ensures that if the default_external + # is set to something other than UTF-8, we don't + # get any errors and get back a UTF-8 String. + def test_default_external_works + with_external_encoding "ISO-8859-1" do + @template = new_template("hello \xFCmlat") assert_equal Encoding::UTF_8, render.encoding assert_equal "hello \u{fc}mlat", render end + end - # This test ensures that if the default_external - # is set to something other than UTF-8, we don't - # get any errors and get back a UTF-8 String. - def test_default_external_works - with_external_encoding "ISO-8859-1" do - @template = new_template("hello \xFCmlat") - assert_equal Encoding::UTF_8, render.encoding - assert_equal "hello \u{fc}mlat", render - end - end - - def test_encoding_can_be_specified_with_magic_comment - @template = new_template("# encoding: ISO-8859-1\nhello \xFCmlat") - assert_equal Encoding::UTF_8, render.encoding - assert_equal "\nhello \u{fc}mlat", render - end + def test_encoding_can_be_specified_with_magic_comment + @template = new_template("# encoding: ISO-8859-1\nhello \xFCmlat") + assert_equal Encoding::UTF_8, render.encoding + assert_equal "\nhello \u{fc}mlat", render + end - # TODO: This is currently handled inside ERB. The case of explicitly - # lying about encodings via the normal Rails API should be handled - # inside Rails. - def test_lying_with_magic_comment - assert_raises(ActionView::Template::Error) do - @template = new_template("# encoding: UTF-8\nhello \xFCmlat", :virtual_path => nil) - render - end + # TODO: This is currently handled inside ERB. The case of explicitly + # lying about encodings via the normal Rails API should be handled + # inside Rails. + def test_lying_with_magic_comment + assert_raises(ActionView::Template::Error) do + @template = new_template("# encoding: UTF-8\nhello \xFCmlat", :virtual_path => nil) + render end + end - def test_encoding_can_be_specified_with_magic_comment_in_erb - with_external_encoding Encoding::UTF_8 do - @template = new_template("<%# encoding: ISO-8859-1 %>hello \xFCmlat", :virtual_path => nil) - assert_equal Encoding::UTF_8, render.encoding - assert_equal "hello \u{fc}mlat", render - end + def test_encoding_can_be_specified_with_magic_comment_in_erb + with_external_encoding Encoding::UTF_8 do + @template = new_template("<%# encoding: ISO-8859-1 %>hello \xFCmlat", :virtual_path => nil) + assert_equal Encoding::UTF_8, render.encoding + assert_equal "hello \u{fc}mlat", render end + end - def test_error_when_template_isnt_valid_utf8 - assert_raises(ActionView::Template::Error, /\xFC/) do - @template = new_template("hello \xFCmlat", :virtual_path => nil) - render - end + def test_error_when_template_isnt_valid_utf8 + assert_raises(ActionView::Template::Error, /\xFC/) do + @template = new_template("hello \xFCmlat", :virtual_path => nil) + render end + end - def with_external_encoding(encoding) - old = Encoding.default_external - Encoding::Converter.new old, encoding if old != encoding - silence_warnings { Encoding.default_external = encoding } - yield - ensure - silence_warnings { Encoding.default_external = old } - end + def with_external_encoding(encoding) + old = Encoding.default_external + Encoding::Converter.new old, encoding if old != encoding + silence_warnings { Encoding.default_external = encoding } + yield + ensure + silence_warnings { Encoding.default_external = old } end end |