rails/actionpack/test/controller/chunked_test.rb
Hartley McGuire a03a854193
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]: 0c334b48fdc5d70b0c8406ba184fbfd26750b049
2024-01-07 14:33:25 -05:00

33 lines
980 B
Ruby

# frozen_string_literal: true
require "stringio"
require "abstract_unit"
class ChunkedTest < ActionDispatch::IntegrationTest
class ChunkedController < ApplicationController
def chunk
render json: {
raw_post: request.raw_post,
content_length: request.content_length
}
end
end
# The TestInput class prevents Rack::MockRequest from adding a Content-Length when the method `size` is defined
class TestInput < StringIO
undef_method :size
end
test "parses request raw_post correctly when request has Transfer-Encoding header without a Content-Length value" do
@app = self.class.build_app
@app.routes.draw do
post "chunked", to: ChunkedController.action(:chunk)
end
post "/chunked", params: TestInput.new("foo=bar"), headers: { "Transfer-Encoding" => "gzip, chunked;foo=bar" }
assert_equal 7, response.parsed_body["content_length"]
assert_equal "foo=bar", response.parsed_body["raw_post"]
end
end