2021-07-31 ActiveStorage attach(attachable) / fixture_file_upload + file_fixture in Rails Test
ActiveStorage::Attached::One attach(attachable) | RailsDoc(β)
person.avatar.attach(params[:avatar]) # ActionDispatch::Http::UploadedFile object
person.avatar.attach(params[:signed_blob_id]) # Signed reference to blob from direct upload
person.avatar.attach(io: File.open("/path/to/face.jpg"), filename: "face.jpg", content_type: "image/jpg")
person.avatar.attach(avatar_blob) # ActiveStorage::Blob object
fixture_file_upload + file_fixture in Rails Test
How to upload a file in a Rails Rspec request spec - Stack Overflow
let(:csv_file) { fixture_file_upload(file_fixture('file_example.csv')) }
subject(:http_request) { post upload_file_path, params: { file: csv_file } }