I could test upload of one file
attach_file 'photo', File.join(Rails.root, 'public', 'uploads', 'test.png')
But what if I have a file field with multiple
atribute? How can I test multiple files upload using Cucumber/Capybara?
HTML:
<input id="fileupload" class="photo-uploader" type="file" multiple="" name="images">
Capybara:
page.attach_file "images", ['path to file1.jpg', 'path to file2.jpg', 'path to file3.jpg']
name
attribute of the <input>
with type="file"
and add it as the first parameter. It seems it is currently not possible with Capybara:
Before testing multiple file uploads you should ask yourself, how you're going to store several photos in one model. One possible solution for this would be:
class Post < ActiveRecord::Base
has_many :photos
end
class Photo < ActiveRecord::Base
belongs_to :post
# if you're using Carrierwave
mount_uploader :photo, PhotoUploader
end
After that you could realize that there's no difference between testing one or many files upload.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.