How to upload a file in a Rails Rspec request spec

前端 未结 5 2189
没有蜡笔的小新
没有蜡笔的小新 2021-02-19 03:20

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\'
para         


        
5条回答
  •  野性不改
    2021-02-19 03:42

    For rails 6 no need to do includes, just fixture_file_upload. If you are using spec/fixtures/files folder for fixtures you can use file_fixture helper

    let(:csv_file) { fixture_file_upload(file_fixture('file_example.csv')) }
    
    subject(:http_request) { post upload_file_path, params: { file: csv_file } }
    

提交回复
热议问题