How do I test a file upload in rails?

后端 未结 7 520
轻奢々
轻奢々 2020-12-07 09:29

I have a controller which is responsible for accepting JSON files and then processing the JSON files to do some user maintenance for our application. In user testing the fil

7条回答
  •  再見小時候
    2020-12-07 10:04

    If you are using default rails test with factory girl. Fine below code.

    factory :image_100_100 do
        image File.new(File.join(::Rails.root.to_s, "/test/images", "100_100.jpg"))
    end
    

    Note: you will have to keep an dummy image in /test/images/100_100.jpg.

    It works perfectly.

    Cheers!

提交回复
热议问题