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

59 lines
1.4 KiB
Ruby
Raw Normal View History

FactoryBot.define do
factory :upload do
model { build(:project) }
size 100.kilobytes
uploader "AvatarUploader"
mount_point :avatar
secret nil
2018-02-21 16:43:21 +00:00
store ObjectStorage::Store::LOCAL
2017-12-06 11:36:11 +00:00
# we should build a mount agnostic upload by default
transient do
filename 'myfile.jpg'
end
# this needs to comply with RecordsUpload::Concern#upload_path
path { File.join("uploads/-/system", model.class.to_s.underscore, mount_point.to_s, 'avatar.jpg') }
trait :personal_snippet_upload do
2017-12-06 11:36:11 +00:00
uploader "PersonalFileUploader"
path { File.join(secret, filename) }
model { build(:personal_snippet) }
secret SecureRandom.hex
2017-12-06 11:36:11 +00:00
end
trait :issuable_upload do
uploader "FileUploader"
path { File.join(secret, filename) }
secret SecureRandom.hex
2017-12-06 11:36:11 +00:00
end
2018-07-10 14:33:40 +00: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 16:43:21 +00:00
trait :object_storage do
store ObjectStorage::Store::REMOTE
end
2017-12-06 11:36:11 +00:00
trait :namespace_upload do
model { build(:group) }
path { File.join(secret, filename) }
2017-12-06 11:36:11 +00:00
uploader "NamespaceFileUploader"
secret SecureRandom.hex
2017-12-06 11:36:11 +00:00
end
trait :attachment_upload do
transient do
mount_point :attachment
end
model { build(:note) }
uploader "AttachmentUploader"
end
end
end