Allow uploading multiple files from your computer at once. The maximum limit is 100 files at once. There is still a 50MB size limit that applies to the whole upload. This limit is at the Nginx level. The upload widget no longer shows a thumbnail preview of the uploaded file. This is because there isn't room for it in a multi-file upload, and because the next page will show a preview anyway after the files are uploaded. Direct file uploads are processed synchronously, so they may be slow. API change: the `POST /uploads` endpoint now expects the param to be `upload[files][]`, not `upload[file]`.
37 lines
1.2 KiB
Ruby
37 lines
1.2 KiB
Ruby
module UploadTestHelper
|
|
extend ActiveSupport::Concern
|
|
|
|
def create_upload!(source_or_file_path, user:, **params)
|
|
if source_or_file_path =~ %r{\Ahttps?://}i
|
|
skip "Login credentials not configured for #{source_or_file_path}" unless Sources::Strategies.find(source_or_file_path).class.enabled?
|
|
source = { source: source_or_file_path }
|
|
else
|
|
file = Rack::Test::UploadedFile.new(Rails.root.join(source_or_file_path))
|
|
source = { files: { "0" => file } }
|
|
end
|
|
|
|
perform_enqueued_jobs do
|
|
post_auth uploads_path(format: :json), user, params: { upload: { **source, **params }}
|
|
end
|
|
end
|
|
|
|
def assert_successful_upload(source_or_file_path, user: create(:user), **params)
|
|
create_upload!(source_or_file_path, user: user, **params)
|
|
|
|
upload = Upload.last
|
|
assert_response 201
|
|
assert_equal("", upload&.error.to_s)
|
|
assert_equal("completed", upload.status)
|
|
assert_operator(upload.media_assets.count, :>, 0)
|
|
upload
|
|
end
|
|
|
|
class_methods do
|
|
def should_upload_successfully(source)
|
|
should "upload successfully from #{source}" do
|
|
assert_successful_upload(source, user: create(:user))
|
|
end
|
|
end
|
|
end
|
|
end
|