mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Document, refactor and create test case for ActionDispatch::Response#charset= method
This commit is contained in:
parent
af01f45f06
commit
422292dc98
2 changed files with 13 additions and 6 deletions
|
@ -187,13 +187,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.
|
||||
|
|
|
@ -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!"
|
||||
|
||||
|
|
Loading…
Reference in a new issue