Skip to content

Commit

Permalink
download PDF properly
Browse files Browse the repository at this point in the history
  • Loading branch information
starswan committed Nov 25, 2024
1 parent 466f9c0 commit 35b581c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def show
def download_pdf
if job_application.pdf_version.attached?
send_data(
job_application.pdf_version.attachment,
job_application.pdf_version.attachment.download,
filename: "job_application_#{job_application.id}.pdf",
type: "application/pdf",
disposition: "inline",
Expand Down
1 change: 1 addition & 0 deletions app/jobs/make_job_application_pdf_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ def perform(job_application)

job_application.pdf_version.attach(io: StringIO.open(pdf_data),
filename: "job_application_#{job_application.id}.pdf",
identify: false,
content_type: "application/pdf")
end
end
1 change: 1 addition & 0 deletions config/initializers/mime_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

# Add new mime types for use in respond_to blocks:
# Mime::Type.register "text/richtext", :rtf
Mime::Type.register "application/pdf", :pdf
20 changes: 20 additions & 0 deletions spec/requests/publishers/vacancies/job_applications_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,26 @@
end
end

describe "download pdf" do
context "without cache" do
it "allows the PDF to be downloaded" do
get(organisation_job_job_application_download_pdf_path(vacancy.id, job_application.id))
expect(response.body).to satisfy { |body| body.size > 128000 }
end
end

context "with cache" do
before do
MakeJobApplicationPdfJob.perform_now job_application
end

it "allows the PDF to be downloaded" do
get(organisation_job_job_application_download_pdf_path(vacancy.id, job_application.id))
expect(response.body).to satisfy { |body| body.size > 128000 }
end
end
end

describe "GET #index" do
context "when the vacancy does not belong to the current organisation" do
let(:vacancy) { create(:vacancy, :published, organisations: [build(:school)]) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
RSpec.describe "Publishers can view a job application" do
let(:publisher) { create(:publisher) }
let(:organisation) { create(:school) }
let(:vacancy) { create(:vacancy, :expired, organisations: [organisation]) }
let(:vacancy) { create(:vacancy, :expired, pay_scale: "things", salary: "more dogh", organisations: [organisation]) }
let(:job_application) { create(:job_application, :status_submitted, vacancy: vacancy) }

before do
Expand Down

0 comments on commit 35b581c

Please sign in to comment.