diff options
Diffstat (limited to 'spec/factories/uploads.rb')
-rw-r--r-- | spec/factories/uploads.rb | 45 |
1 files changed, 25 insertions, 20 deletions
diff --git a/spec/factories/uploads.rb b/spec/factories/uploads.rb index 3f6326114c9..a060cd7d6f8 100644 --- a/spec/factories/uploads.rb +++ b/spec/factories/uploads.rb @@ -2,32 +2,36 @@ FactoryBot.define do factory :upload do - model { build(:project) } + model { create(:project) } size { 100.kilobytes } - uploader "AvatarUploader" - mount_point :avatar - secret nil - store ObjectStorage::Store::LOCAL + uploader { "AvatarUploader" } + mount_point { :avatar } + secret { nil } + store { ObjectStorage::Store::LOCAL } # we should build a mount agnostic upload by default transient do - filename 'myfile.jpg' + filename { 'avatar.jpg' } end - # this needs to comply with RecordsUpload::Concern#upload_path - path { File.join("uploads/-/system", model.class.underscore, mount_point.to_s, 'avatar.jpg') } + 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 - uploader "PersonalFileUploader" + model { create(:personal_snippet) } path { File.join(secret, filename) } - model { build(:personal_snippet) } + uploader { "PersonalFileUploader" } secret { SecureRandom.hex } + mount_point { nil } end trait :issuable_upload do - uploader "FileUploader" + uploader { "FileUploader" } path { File.join(secret, filename) } secret { SecureRandom.hex } + mount_point { nil } end trait :with_file do @@ -38,27 +42,28 @@ FactoryBot.define do end trait :object_storage do - store ObjectStorage::Store::REMOTE + store { ObjectStorage::Store::REMOTE } end trait :namespace_upload do - model { build(:group) } + model { create(:group) } path { File.join(secret, filename) } - uploader "NamespaceFileUploader" + uploader { "NamespaceFileUploader" } secret { SecureRandom.hex } + mount_point { nil } end trait :favicon_upload do - model { build(:appearance) } - path { File.join(secret, filename) } - uploader "FaviconUploader" + model { create(:appearance) } + uploader { "FaviconUploader" } secret { SecureRandom.hex } + mount_point { :favicon } end trait :attachment_upload do - mount_point :attachment - model { build(:note) } - uploader "AttachmentUploader" + mount_point { :attachment } + model { create(:note) } + uploader { "AttachmentUploader" } end end end |