diff options
author | Rafael França <rafaelmfranca@gmail.com> | 2016-11-17 19:00:18 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-11-17 19:00:18 -0500 |
commit | 796049ef3e0c526a2c97418d4ba266050bc38c0a (patch) | |
tree | ff4e699cf86afa9695c8df551769fba0ec45db2d | |
parent | c659cb8561f03c2e0b29da0379a9c341400e03bd (diff) | |
parent | b388ca41d8b26f027a43e96c5ad0950a6bf2f5d7 (diff) | |
download | rails-796049ef3e0c526a2c97418d4ba266050bc38c0a.tar.gz rails-796049ef3e0c526a2c97418d4ba266050bc38c0a.tar.bz2 rails-796049ef3e0c526a2c97418d4ba266050bc38c0a.zip |
Merge pull request #26551 from mgpnd/FixContentLength
Fixed CONTENT_LENGTH header in ActionController::TestRequest
-rw-r--r-- | actionpack/lib/action_controller/test_case.rb | 5 | ||||
-rw-r--r-- | actionpack/test/controller/request/test_request_test.rb | 10 |
2 files changed, 13 insertions, 2 deletions
diff --git a/actionpack/lib/action_controller/test_case.rb b/actionpack/lib/action_controller/test_case.rb index 33c0201951..85f2501d42 100644 --- a/actionpack/lib/action_controller/test_case.rb +++ b/actionpack/lib/action_controller/test_case.rb @@ -112,8 +112,9 @@ module ActionController end end - set_header "CONTENT_LENGTH", data.length.to_s - set_header "rack.input", StringIO.new(data) + data_stream = StringIO.new(data) + set_header "CONTENT_LENGTH", data_stream.length.to_s + set_header "rack.input", data_stream end fetch_header("PATH_INFO") do |k| diff --git a/actionpack/test/controller/request/test_request_test.rb b/actionpack/test/controller/request/test_request_test.rb index fa049fbc9f..da6fa1388b 100644 --- a/actionpack/test/controller/request/test_request_test.rb +++ b/actionpack/test/controller/request/test_request_test.rb @@ -11,6 +11,16 @@ class ActionController::TestRequestTest < ActionController::TestCase assert_equal nil, ActionController::TestSession::DEFAULT_OPTIONS[:myparam] end + def test_content_length_has_bytes_count_value + non_ascii_parameters = { data: { content: "Latin + Кириллица" } } + @request.set_header "REQUEST_METHOD", "POST" + @request.set_header "CONTENT_TYPE", "application/json" + @request.assign_parameters(@routes, "test", "create", non_ascii_parameters, + "/test", [:data, :controller, :action]) + assert_equal(@request.get_header("CONTENT_LENGTH"), + StringIO.new(non_ascii_parameters.to_json).length.to_s) + end + ActionDispatch::Session::AbstractStore::DEFAULT_OPTIONS.each_key do |option| test "rack default session options #{option} exists in session options and is default" do assert_equal(ActionDispatch::Session::AbstractStore::DEFAULT_OPTIONS[option], |