Skip to content

Commit cab76c3

Browse files
committed
Fix binary court report downloads
1 parent 8e893b1 commit cab76c3

2 files changed

Lines changed: 20 additions & 7 deletions

File tree

app/controllers/case_court_reports_controller.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,11 @@ def show
2424
respond_to do |format|
2525
format.docx do
2626
@casa_case.latest_court_report.open do |file|
27-
# TODO test this .read being present, we've broken it twice now
28-
send_data File.read(file.path), type: :docx, disposition: "attachment", status: :ok
27+
send_data File.binread(file.path),
28+
type: :docx,
29+
filename: "#{@casa_case.case_number}.docx",
30+
disposition: "attachment",
31+
status: :ok
2932
end
3033
end
3134
end

spec/requests/case_court_reports_spec.rb

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,14 @@
5353
end
5454

5555
let(:casa_case) { volunteer.casa_cases.first }
56+
let(:case_number) { "#C-15-JV-24-191" }
57+
let(:report_bytes) { Rails.root.join("spec/fixtures/files/default_past_court_date_template.docx").binread }
5658

5759
before do
58-
Tempfile.create do |t|
59-
casa_case.court_reports.attach(
60-
io: File.open(t.path), filename: "#{casa_case.case_number}.docx"
61-
)
62-
end
60+
casa_case.update!(case_number: case_number)
61+
casa_case.court_reports.attach(
62+
io: StringIO.new(report_bytes), filename: "stored-report.docx"
63+
)
6364
end
6465

6566
it "authorizes action" do
@@ -74,6 +75,15 @@
7475
it "send response with a status :ok" do
7576
expect(request).to have_http_status(:ok)
7677
end
78+
79+
it "sends the stored report bytes using the case number as the filename", :aggregate_failures do
80+
expect(request.body).to eq(report_bytes)
81+
expect(request.body.bytesize).to eq(casa_case.latest_court_report.blob.byte_size)
82+
expect(request.body).to start_with("PK\x03\x04".b)
83+
expect(request.headers["Content-Disposition"]).to include(
84+
%(attachment; filename="#{casa_case.case_number}.docx")
85+
)
86+
end
7787
end
7888

7989
context "when an INVALID / non-existing case is sent" do

0 commit comments

Comments
 (0)