Skip to content

Commit a03a854

Browse files
committed
Move Transfer-Encoding chunked test to Action Pack
While working on [another PR][1], I found that removing the Transfer-Encoding conditionals did not result in any failing tests in Action Pack. This was surprising to me until I found that there was a test for this behavior in Railties. However, nothing about the test really depends on having a full Rails application or the Railties test suite. This commit moves the test into Action Pack to simplify/speedup the test (no need to build a full app) as well as keeping the test closer to the actual behavior being tested. [1]: 0c334b4
1 parent 7f34113 commit a03a854

File tree

2 files changed

+32
-54
lines changed

2 files changed

+32
-54
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# frozen_string_literal: true
2+
3+
require "stringio"
4+
require "abstract_unit"
5+
6+
class ChunkedTest < ActionDispatch::IntegrationTest
7+
class ChunkedController < ApplicationController
8+
def chunk
9+
render json: {
10+
raw_post: request.raw_post,
11+
content_length: request.content_length
12+
}
13+
end
14+
end
15+
16+
# The TestInput class prevents Rack::MockRequest from adding a Content-Length when the method `size` is defined
17+
class TestInput < StringIO
18+
undef_method :size
19+
end
20+
21+
test "parses request raw_post correctly when request has Transfer-Encoding header without a Content-Length value" do
22+
@app = self.class.build_app
23+
@app.routes.draw do
24+
post "chunked", to: ChunkedController.action(:chunk)
25+
end
26+
27+
post "/chunked", params: TestInput.new("foo=bar"), headers: { "Transfer-Encoding" => "gzip, chunked;foo=bar" }
28+
29+
assert_equal 7, response.parsed_body["content_length"]
30+
assert_equal "foo=bar", response.parsed_body["raw_post"]
31+
end
32+
end

railties/test/railties/http_request_test.rb

Lines changed: 0 additions & 54 deletions
This file was deleted.

0 commit comments

Comments
 (0)