diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-07-27 17:31:24 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2015-07-27 17:31:24 -0300 |
commit | 32b0db266ced3f370d4e989c93a074002153a1c1 (patch) | |
tree | 8de908f294f82822683f8891c12842f963ba3295 /actionpack | |
parent | 722b2729b04954f92a04acd0a28efeb6eb1b7d6d (diff) | |
parent | 422292dc98cf42b20758025bf55b5b84260aecb4 (diff) | |
download | rails-32b0db266ced3f370d4e989c93a074002153a1c1.tar.gz rails-32b0db266ced3f370d4e989c93a074002153a1c1.tar.bz2 rails-32b0db266ced3f370d4e989c93a074002153a1c1.zip |
Merge pull request #20590 from vngrs/set_default_charset
Document, refactor and create test case for ActionDispatch::Response
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_dispatch/http/response.rb | 12 | ||||
-rw-r--r-- | actionpack/test/dispatch/response_test.rb | 7 |
2 files changed, 13 insertions, 6 deletions
diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb index eab7d0ab57..37e26faffb 100644 --- a/actionpack/lib/action_dispatch/http/response.rb +++ b/actionpack/lib/action_dispatch/http/response.rb @@ -197,13 +197,13 @@ module ActionDispatch # :nodoc: @content_type = content_type.to_s end - # Sets the HTTP character set. + # Sets the HTTP character set. In case of nil parameter + # it sets the charset to utf-8. + # + # response.charset = 'utf-16' # => 'utf-16' + # response.charset = nil # => 'utf-8' def charset=(charset) - if nil == charset - @charset = self.class.default_charset - else - @charset = charset - end + @charset = charset.nil? ? self.class.default_charset : charset end # The response code of the request. diff --git a/actionpack/test/dispatch/response_test.rb b/actionpack/test/dispatch/response_test.rb index 5aa0215e8f..780e7dc3e2 100644 --- a/actionpack/test/dispatch/response_test.rb +++ b/actionpack/test/dispatch/response_test.rb @@ -42,6 +42,13 @@ class ResponseTest < ActiveSupport::TestCase assert_equal Encoding::UTF_8, response.body.encoding end + def test_response_charset_writer + @response.charset = 'utf-16' + assert_equal 'utf-16', @response.charset + @response.charset = nil + assert_equal 'utf-8', @response.charset + end + test "simple output" do @response.body = "Hello, World!" |