diff options
author | Yves Senn <yves.senn@gmail.com> | 2014-05-28 15:50:24 +0200 |
---|---|---|
committer | Yves Senn <yves.senn@gmail.com> | 2014-05-28 15:50:24 +0200 |
commit | 0f80a5262964c27b3204c8179d37f91c64ceb6f6 (patch) | |
tree | 2dbabcc6e225a66c64b29cd125d3554ddc3b6e81 /actionpack | |
parent | bdbf00dc78869f91a8af4d56a19213faf2b8d9e5 (diff) | |
parent | 51dc7c2adb78c3593c72f79d59263c57bbc63588 (diff) | |
download | rails-0f80a5262964c27b3204c8179d37f91c64ceb6f6.tar.gz rails-0f80a5262964c27b3204c8179d37f91c64ceb6f6.tar.bz2 rails-0f80a5262964c27b3204c8179d37f91c64ceb6f6.zip |
Merge pull request #15381 from zuhao/refactor_actionpack_content_type_test
Add with_default_charset helper.
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/test/controller/content_type_test.rb | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/actionpack/test/controller/content_type_test.rb b/actionpack/test/controller/content_type_test.rb index 03d5d27cf4..89667df3a4 100644 --- a/actionpack/test/controller/content_type_test.rb +++ b/actionpack/test/controller/content_type_test.rb @@ -68,12 +68,11 @@ class ContentTypeTest < ActionController::TestCase end def test_render_changed_charset_default - ActionDispatch::Response.default_charset = "utf-16" - get :render_defaults - assert_equal "utf-16", @response.charset - assert_equal Mime::HTML, @response.content_type - ensure - ActionDispatch::Response.default_charset = "utf-8" + with_default_charset "utf-16" do + get :render_defaults + assert_equal "utf-16", @response.charset + assert_equal Mime::HTML, @response.content_type + end end # :ported: @@ -105,12 +104,11 @@ class ContentTypeTest < ActionController::TestCase end def test_nil_default_for_erb - ActionDispatch::Response.default_charset = nil - get :render_default_for_erb - assert_equal Mime::HTML, @response.content_type - assert_nil @response.charset, @response.headers.inspect - ensure - ActionDispatch::Response.default_charset = "utf-8" + with_default_charset nil do + get :render_default_for_erb + assert_equal Mime::HTML, @response.content_type + assert_nil @response.charset, @response.headers.inspect + end end def test_default_for_erb @@ -130,6 +128,16 @@ class ContentTypeTest < ActionController::TestCase assert_equal Mime::HTML, @response.content_type assert_equal "utf-8", @response.charset end + + private + + def with_default_charset(charset) + old_default_charset = ActionDispatch::Response.default_charset + ActionDispatch::Response.default_charset = charset + yield + ensure + ActionDispatch::Response.default_charset = old_default_charset + end end class AcceptBasedContentTypeTest < ActionController::TestCase |