Skip to content

Commit

Permalink
The respond_to is pointless
Browse files Browse the repository at this point in the history
since the block is still expected to be written by the user, so it calls the same methods
  • Loading branch information
julik committed Mar 29, 2024
1 parent a1b6280 commit a2f8bc2
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 53 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* Include `RailsStreaming` automatically via a Railtie. It is not really necessary to force people to manage it manually.

## 6.2.2

* Make sure "zlib" gets required at the top, as it is used everywhere
Expand Down
4 changes: 0 additions & 4 deletions lib/zip_kit/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,5 @@
class ZipKit::Railtie < ::Rails::Railtie
initializer "zip_kit.install_extensions" do |app|
ActionController::Base.include(ZipKit::RailsStreaming)
ActionController::Renderers.add :zip do |obj, options, &blk|
warn "zip renderer"
zip_kit_stream(**options, &blk)
end
end
end
49 changes: 0 additions & 49 deletions spec/zip_kit/rails_streaming_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,14 +60,6 @@ def stream_zip_with_custom_content_type
generator.generate_once(z)
end
end

def show
generator = FakeZipGenerator.new
respond_to do |format|
format.html { render inline: "<h1>Hello</h1>" }
format.zip { zip_kit_stream { |zip| generator.generate_once(zip) } }
end
end
end

it "degrades to a buffered response with HTTP/1.0 and produces a ZIP" do
Expand Down Expand Up @@ -95,47 +87,6 @@ def show
# All the other methods have been excercised by reading out the iterable body
end

it "is able to serve a ZIP via respond_to" do
fake_rack_env_html = {
"HTTP_VERSION" => "HTTP/1.0",
"REQUEST_METHOD" => "GET",
"SCRIPT_NAME" => "",
"PATH_INFO" => "/download.html",
"QUERY_STRING" => "",
"SERVER_NAME" => "host.example",
"rack.input" => StringIO.new
}
status, headers, body = FakeController.action(:show).call(fake_rack_env_html)
out = readback_iterable(body)
expect(out.string).to eq("<h1>Hello</h1>")
expect(headers["Content-Type"]).to eq("text/html; charset=utf-8")

fake_rack_env = {
"HTTP_VERSION" => "HTTP/1.0",
"REQUEST_METHOD" => "GET",
"SCRIPT_NAME" => "",
"PATH_INFO" => "/download.zip",
"QUERY_STRING" => "",
"SERVER_NAME" => "host.example",
"rack.input" => StringIO.new
}

ref_output_io = FakeZipGenerator.generate_reference
status, headers, body = FakeController.action(:show).call(fake_rack_env)
out = readback_iterable(body)

expect(out.string).to eq(ref_output_io.string)
expect { body.close }.not_to raise_error
expect(status).to eq(200)
expect_correct_headers!(headers)

expect(headers["Content-Type"]).to eq("application/zip")
expect(headers["X-Accel-Buffering"]).to eq("no")
expect(headers["Transfer-Encoding"]).to be_nil
expect(headers["Content-Length"]).to be_kind_of(String)
# All the other methods have been excercised by reading out the iterable body
end

it "uses Transfer-Encoding: chunked when requested" do
fake_rack_env = {
"HTTP_VERSION" => "HTTP/1.1",
Expand Down

0 comments on commit a2f8bc2

Please sign in to comment.