From b5f908a7ad515215f164e306f82c3e6c506182cb Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Thu, 3 Nov 2011 16:09:57 +0000 Subject: Stub find_template so that when handle_render_error is called in ActionView::Template, we get to see the actual underlying error rather than a NoMethodError. This shows an encoding bug on Ruby 1.9.3. --- actionpack/test/template/template_test.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'actionpack/test/template/template_test.rb') diff --git a/actionpack/test/template/template_test.rb b/actionpack/test/template/template_test.rb index b0ca7de0b6..70ca876c67 100644 --- a/actionpack/test/template/template_test.rb +++ b/actionpack/test/template/template_test.rb @@ -8,6 +8,9 @@ class TestERBTemplate < ActiveSupport::TestCase def disable_cache yield end + + def find_template(*args) + end end class Context -- cgit v1.2.3 From 10773f94eae0dacf10e2ed0c28f6bb73805c2521 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Sat, 5 Nov 2011 16:42:53 +0000 Subject: Skip test_default_external_works on the CI for Ruby 1.9.3. This test is affected by a bug in Ruby 1.9.3p0 and trunk: http://redmine.ruby-lang.org/issues/5564 Given we cannot fix it for ourselves, it is better to skip for now so that we will easily see if further failures are introduced. Jon Leighton is monitoring the bug report and will revert this when a suitable solution is found (either a new Ruby release or a generic workaround). If you are using 1.9.3 in your app and have templates that are not in UTF-8, you should add a workaround early on in the boot process. For example, if your templates are Shift_JIS encoded, then add the following in an initializer: Encoding::Converter.new('Shift_JIS', 'UTF-8') --- actionpack/test/template/template_test.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'actionpack/test/template/template_test.rb') diff --git a/actionpack/test/template/template_test.rb b/actionpack/test/template/template_test.rb index 70ca876c67..f3328b5dca 100644 --- a/actionpack/test/template/template_test.rb +++ b/actionpack/test/template/template_test.rb @@ -130,6 +130,17 @@ class TestERBTemplate < ActiveSupport::TestCase # 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 + if ENV['TRAVIS'] && RUBY_VERSION >= '1.9.3' + skip( + "There is currently a bug in Ruby trunk and in 1.9.3 which makes this test fail. " \ + "Please see http://redmine.ruby-lang.org/issues/5564. " \ + "Given there is no known generic workaround that this requires a fix in Ruby itself, " \ + "this test is skipped on the CI for now so that we don't pollute the CI with failures. " \ + "Jon Leighton is monitoring the bug report and will renable this test when a solution " \ + "becomes available." + ) + end + with_external_encoding "ISO-8859-1" do @template = new_template("hello \xFCmlat") assert_equal Encoding::UTF_8, render.encoding -- cgit v1.2.3 From 7776055e2dcd29e0f8f27154663263c0bbd1c188 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Sun, 6 Nov 2011 10:15:04 +0000 Subject: Revert "Skip test_default_external_works on the CI for Ruby 1.9.3." This reverts commit 10773f94eae0dacf10e2ed0c28f6bb73805c2521. --- actionpack/test/template/template_test.rb | 11 ----------- 1 file changed, 11 deletions(-) (limited to 'actionpack/test/template/template_test.rb') diff --git a/actionpack/test/template/template_test.rb b/actionpack/test/template/template_test.rb index f3328b5dca..70ca876c67 100644 --- a/actionpack/test/template/template_test.rb +++ b/actionpack/test/template/template_test.rb @@ -130,17 +130,6 @@ class TestERBTemplate < ActiveSupport::TestCase # 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 - if ENV['TRAVIS'] && RUBY_VERSION >= '1.9.3' - skip( - "There is currently a bug in Ruby trunk and in 1.9.3 which makes this test fail. " \ - "Please see http://redmine.ruby-lang.org/issues/5564. " \ - "Given there is no known generic workaround that this requires a fix in Ruby itself, " \ - "this test is skipped on the CI for now so that we don't pollute the CI with failures. " \ - "Jon Leighton is monitoring the bug report and will renable this test when a solution " \ - "becomes available." - ) - end - with_external_encoding "ISO-8859-1" do @template = new_template("hello \xFCmlat") assert_equal Encoding::UTF_8, render.encoding -- cgit v1.2.3 From 2c471b3ac805b00ac1423f7ae2be1554aca0db9f Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Thu, 8 Dec 2011 15:11:23 -0800 Subject: load the encoding converter to work around [ruby-core:41556] when switching encodings --- actionpack/test/template/template_test.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'actionpack/test/template/template_test.rb') diff --git a/actionpack/test/template/template_test.rb b/actionpack/test/template/template_test.rb index 70ca876c67..fe82504d3b 100644 --- a/actionpack/test/template/template_test.rb +++ b/actionpack/test/template/template_test.rb @@ -170,6 +170,7 @@ class TestERBTemplate < ActiveSupport::TestCase def with_external_encoding(encoding) old = Encoding.default_external + Encoding::Converter.new old, encoding silence_warnings { Encoding.default_external = encoding } yield ensure -- cgit v1.2.3 From c212a34e1d1e2a4bfb546a664958aba168892c49 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Fri, 9 Dec 2011 09:33:36 -0800 Subject: only load converter if the encodings are different --- actionpack/test/template/template_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'actionpack/test/template/template_test.rb') diff --git a/actionpack/test/template/template_test.rb b/actionpack/test/template/template_test.rb index fe82504d3b..13d30a93ce 100644 --- a/actionpack/test/template/template_test.rb +++ b/actionpack/test/template/template_test.rb @@ -170,7 +170,7 @@ class TestERBTemplate < ActiveSupport::TestCase def with_external_encoding(encoding) old = Encoding.default_external - Encoding::Converter.new old, encoding + Encoding::Converter.new old, encoding if old != encoding silence_warnings { Encoding.default_external = encoding } yield ensure -- cgit v1.2.3 From 5ca86ac8f924b333a5a01a47cc07cbcf39c16e80 Mon Sep 17 00:00:00 2001 From: Sergey Nartimov Date: Sat, 24 Dec 2011 15:57:54 +0300 Subject: deprecate String#encoding_aware? and remove its usage --- actionpack/test/template/template_test.rb | 98 +++++++++++++++---------------- 1 file changed, 48 insertions(+), 50 deletions(-) (limited to 'actionpack/test/template/template_test.rb') 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 -- cgit v1.2.3