gitlab-org--gitlab-foss/spec/factories/uploads.rb

76 lines
1.9 KiB
Ruby
Raw Normal View History

# frozen_string_literal: true
FactoryBot.define do
factory :upload do
model { create(:project) }
size { 100.kilobytes }
uploader { "AvatarUploader" }
mount_point { :avatar }
secret { nil }
store { ObjectStorage::Store::LOCAL }
2017-12-06 06:36:11 -05:00
# we should build a mount agnostic upload by default
transient do
filename { 'avatar.jpg' }
end
path do
uploader_instance = Object.const_get(uploader.to_s, false).new(model, mount_point)
File.join(uploader_instance.store_dir, filename)
end
trait :personal_snippet_upload do
model { create(:personal_snippet) }
path { File.join(secret, filename) }
uploader { "PersonalFileUploader" }
secret { SecureRandom.hex }
mount_point { nil }
2017-12-06 06:36:11 -05:00
end
trait :issuable_upload do
uploader { "FileUploader" }
path { File.join(secret, filename) }
secret { SecureRandom.hex }
mount_point { nil }
2017-12-06 06:36:11 -05:00
end
2018-07-10 10:33:40 -04:00
trait :with_file do
after(:create) do |upload|
FileUtils.mkdir_p(File.dirname(upload.absolute_path))
FileUtils.touch(upload.absolute_path)
end
end
2018-02-21 11:43:21 -05:00
trait :object_storage do
store { ObjectStorage::Store::REMOTE }
2018-02-21 11:43:21 -05:00
end
2017-12-06 06:36:11 -05:00
trait :namespace_upload do
model { create(:group) }
path { File.join(secret, filename) }
uploader { "NamespaceFileUploader" }
secret { SecureRandom.hex }
mount_point { nil }
2017-12-06 06:36:11 -05:00
end
trait :favicon_upload do
model { create(:appearance) }
uploader { "FaviconUploader" }
secret { SecureRandom.hex }
mount_point { :favicon }
end
trait :attachment_upload do
mount_point { :attachment }
model { create(:note) }
uploader { "AttachmentUploader" }
end
trait :design_action_image_v432x230_upload do
mount_point { :image_v432x230 }
model { create(:design_action) }
uploader { ::DesignManagement::DesignV432x230Uploader.name }
end
end
end