Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions app/controllers/case_court_reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ def show
respond_to do |format|
format.docx do
@casa_case.latest_court_report.open do |file|
# TODO test this .read being present, we've broken it twice now
send_data File.read(file.path), type: :docx, disposition: "attachment", status: :ok
send_data File.binread(file.path),
type: :docx,
filename: "#{@casa_case.case_number}.docx",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: put filename-ok-formatted timestamp in this (time as well as date)

disposition: "attachment",
status: :ok
end
end
end
Expand Down
20 changes: 15 additions & 5 deletions spec/requests/case_court_reports_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,14 @@
end

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

before do
Tempfile.create do |t|
casa_case.court_reports.attach(
io: File.open(t.path), filename: "#{casa_case.case_number}.docx"
)
end
casa_case.update!(case_number: case_number)
casa_case.court_reports.attach(
io: StringIO.new(report_bytes), filename: "stored-report.docx"
)
end

it "authorizes action" do
Expand All @@ -74,6 +75,15 @@
it "send response with a status :ok" do
expect(request).to have_http_status(:ok)
end

it "sends the stored report bytes using the case number as the filename", :aggregate_failures do

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice aggregate_failures :)

expect(request.body).to eq(report_bytes)
expect(request.body.bytesize).to eq(casa_case.latest_court_report.blob.byte_size)
expect(request.body).to start_with("PK\x03\x04".b)
expect(request.headers["Content-Disposition"]).to include(
%(attachment; filename="#{casa_case.case_number}.docx")
)
end
end

context "when an INVALID / non-existing case is sent" do
Expand Down
Loading