Read more

Spreewald: Content-Disposition not set when testing a download's filename

Emanuel
September 21, 2017Software engineer at makandra GmbH

Precondition

  • You are not using javascript tests
  • The file is served from a public folder (not via controller)

Problem description

If you deliver files from a public folder it might be that the Content-Disposition header is not set. That's why the following spreewald Show archive.org snapshot step might raise an error:

Then I should get a download with filename "..."
expected: /filename="some.pdf"$/
     got: nil (using =~) (RSpec::Expectations::ExpectationNotMetError)

Solution

Illustration online protection

Rails Long Term Support

Rails LTS provides security patches for old versions of Ruby on Rails (2.3, 3.2, 4.2 and 5.2)

  • Prevents you from data breaches and liability risks
  • Upgrade at your own pace
  • Works with modern Rubies
Read more Show archive.org snapshot

One solution is to check the Content-Type header only with the following spreewald Show archive.org snapshot step:

Then I should get a response with content-type "..."

Outline

How to test file downloads with tests that need javascript.

Public served

  • Look at the link of the url and check if this file exists in your public folder (Example for an image)

Server via controller

  • Write an own step which downloads the file and then makes tests with it (you can not check the url because this would be something like localhost:3000/users/4/avatar/3)
  • Override the send_file method of your controller (maybe application controller is also fine): If you are in the test suite return a text with the name of the file. Otherwise super.

Read the browser downloads folder

Posted by Emanuel to makandra dev (2017-09-21 10:57)