0

My rails app contains code to handle large file uploads, which basically consists of splitting up the file in javascript and making a number of posts for each chunk to a route where they are then reconstructed back to the original file.

I'm trying to figure out how to write tests for this logic, as up until now I've simply used fixture_file_upload for posting files.

I basically need to split a given file up into a range of bytes, and post that in a way that my route would handle it just as though it has been posted by my javascript.

Anyone know of a way to accomplish this in a rails test?

4

1 回答 1

0

您可以只创建多个夹具文件(例如file.part1.txtfile.part2.txt等),上传所有部分,然后检查它们是否连接在一起。

例如,如果有 10 个夹具文件:

(1..10).each do |part_no|
  fixture_name = "file.part#{part_no}.txt"
  fixture_file = fixture_file_upload("/files/#{fixture_name}", "text/plain")
  post :part_upload, :part => fixture_file
end
# code to check result here
于 2013-08-26T23:53:18.373 回答