Broken image links while using system tests

I’m successfully able to upload images using fixtures and the TestData module from the documentation when using Rails’ system tests (Rails 5.2). However, whenever the Selenium browser opens up, all the uploaded test images have broken links. The files all exist locally and were uploaded using'tmp/uploads'). Any thoughts on why the links are broken?

<img src="/Users/me/projects/test_app/tmp/uploads/ac220637db69c0348120bff043b50a84">

The image file exists at /Users/me/projects/test_app/tmp/uploads/ac220637db69c0348120bff043b50a84 but when I copy and visit the full URL at it redirects me back to the page instead of the image file.

Side note:
In order to get my fixture .yml file to properly load the TestData image url, I had to do the following:

image_data: > 
  <%= TestData.image_data %> 

otherwise, there is a JSON parsing error and Rails will add --- to the beginning of the JSON image data. Perhaps the testing documentation should be updated unless this is only a Rails 5.2 bug.

For system tests you probably need to upload files to the public/ directory folder, and generates relative URLs from the public/ directory, just like you would if you would be using FileSystem storage in development.

Either that, or generate src links that start with file://, so that the browser knows it’s a local file.

That worked beautifully! I also added:

teardown do"public").delete_prefixed("uploads/")

to delete all the uploaded file attachments at the end of the test run. Let me know if this is a good strategy or if you have better suggestions. Thanks again for your help!