debian-mirror-gitlab/spec/factories/uploads.rb

70 lines
1.7 KiB
Ruby
Raw Normal View History

2019-10-12 21:52:04 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
FactoryBot.define do
2017-08-17 22:00:37 +05:30
factory :upload do
2019-12-21 20:55:43 +05:30
model { create(:project) }
2018-12-05 23:21:45 +05:30
size { 100.kilobytes }
2019-12-21 20:55:43 +05:30
uploader { "AvatarUploader" }
mount_point { :avatar }
secret { nil }
store { ObjectStorage::Store::LOCAL }
2018-03-17 18:26:18 +05:30
# we should build a mount agnostic upload by default
transient do
2019-12-21 20:55:43 +05:30
filename { 'avatar.jpg' }
2018-03-17 18:26:18 +05:30
end
2019-12-21 20:55:43 +05:30
path do
uploader_instance = Object.const_get(uploader.to_s, false).new(model, mount_point)
File.join(uploader_instance.store_dir, filename)
end
2018-03-17 18:26:18 +05:30
trait :personal_snippet_upload do
2019-12-21 20:55:43 +05:30
model { create(:personal_snippet) }
2018-03-17 18:26:18 +05:30
path { File.join(secret, filename) }
2019-12-21 20:55:43 +05:30
uploader { "PersonalFileUploader" }
2018-12-05 23:21:45 +05:30
secret { SecureRandom.hex }
2019-12-21 20:55:43 +05:30
mount_point { nil }
2018-03-17 18:26:18 +05:30
end
trait :issuable_upload do
2019-12-21 20:55:43 +05:30
uploader { "FileUploader" }
2018-03-17 18:26:18 +05:30
path { File.join(secret, filename) }
2018-12-05 23:21:45 +05:30
secret { SecureRandom.hex }
2019-12-21 20:55:43 +05:30
mount_point { nil }
2018-03-17 18:26:18 +05:30
end
2018-11-08 19:23:39 +05:30
trait :with_file do
after(:create) do |upload|
FileUtils.mkdir_p(File.dirname(upload.absolute_path))
FileUtils.touch(upload.absolute_path)
end
end
2018-05-09 12:01:36 +05:30
trait :object_storage do
2019-12-21 20:55:43 +05:30
store { ObjectStorage::Store::REMOTE }
2018-05-09 12:01:36 +05:30
end
2018-03-17 18:26:18 +05:30
trait :namespace_upload do
2019-12-21 20:55:43 +05:30
model { create(:group) }
2018-03-17 18:26:18 +05:30
path { File.join(secret, filename) }
2019-12-21 20:55:43 +05:30
uploader { "NamespaceFileUploader" }
2018-12-05 23:21:45 +05:30
secret { SecureRandom.hex }
2019-12-21 20:55:43 +05:30
mount_point { nil }
2018-03-17 18:26:18 +05:30
end
2018-11-20 20:47:30 +05:30
trait :favicon_upload do
2019-12-21 20:55:43 +05:30
model { create(:appearance) }
uploader { "FaviconUploader" }
2018-12-05 23:21:45 +05:30
secret { SecureRandom.hex }
2019-12-21 20:55:43 +05:30
mount_point { :favicon }
2018-11-20 20:47:30 +05:30
end
2018-03-17 18:26:18 +05:30
trait :attachment_upload do
2019-12-21 20:55:43 +05:30
mount_point { :attachment }
model { create(:note) }
uploader { "AttachmentUploader" }
2018-03-17 18:26:18 +05:30
end
2017-08-17 22:00:37 +05:30
end
end