I want to test uploading a file in a Rails Rspec request test. I'm using Paperclip for asset storage.
I've tried:
path = 'path/to/fixture_file'
params = { file: Rack::Test::UploadedFile.new(path, 'application/pdf', true) }
post v1_product_documents_path, params: params
In the controller, I get a string
"#Rack::Test::UploadedFile:0x0055b544479128>"
instead of the actual file.
The same code works in controller tests
try to use fixture_file_upload: fixture_file_upload
or if you wanted to use this in a factory
Rack::Test::UploadedFile.new(File.open(File.join(Rails.root, '/spec/fixtures/images/bob-weir.jpg')))
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With