1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #20590 from vngrs/set_default_charset

Document, refactor and create test case for ActionDispatch::Response
This commit is contained in:
Rafael Mendonça França 2015-07-27 17:31:24 -03:00
commit 32b0db266c
2 changed files with 13 additions and 6 deletions

View file

@ -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.

View file

@ -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!"