2019-04-29 19:27:42 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-06-16 19:46:42 -05:00
|
|
|
Fabricator(:upload) do
|
|
|
|
user
|
2020-06-02 23:23:46 -05:00
|
|
|
sha1 { sequence(:sha1) { |n| Digest::SHA1.hexdigest("#{n}#{Process.pid}") } }
|
2014-04-14 15:55:57 -05:00
|
|
|
original_filename "logo.png"
|
2013-06-16 19:46:42 -05:00
|
|
|
filesize 1234
|
|
|
|
width 100
|
|
|
|
height 200
|
2018-10-04 09:00:07 -05:00
|
|
|
thumbnail_width 30
|
|
|
|
thumbnail_height 60
|
2018-09-14 00:42:59 -05:00
|
|
|
|
|
|
|
url do |attrs|
|
|
|
|
sequence(:url) do |n|
|
|
|
|
Discourse.store.get_path_for(
|
|
|
|
"original", n + 1, attrs[:sha1], ".#{attrs[:extension]}"
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-03 12:08:59 -05:00
|
|
|
extension "png"
|
2013-06-16 19:46:42 -05:00
|
|
|
end
|
2013-07-10 15:59:07 -05:00
|
|
|
|
2020-03-26 09:40:00 -05:00
|
|
|
Fabricator(:image_upload, from: :upload) do
|
|
|
|
after_create do |upload|
|
|
|
|
file = Tempfile.new(['fabricated', '.png'])
|
|
|
|
`convert -size #{upload.width}x#{upload.height} xc:white "#{file.path}"`
|
|
|
|
|
|
|
|
upload.url = Discourse.store.store_upload(file, upload)
|
|
|
|
upload.sha1 = Upload.generate_digest(file.path)
|
|
|
|
|
|
|
|
WebMock
|
|
|
|
.stub_request(:get, "http://#{Discourse.current_hostname}#{upload.url}")
|
|
|
|
.to_return(status: 200, body: File.new(file.path))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-16 07:35:17 -05:00
|
|
|
Fabricator(:video_upload, from: :upload) do
|
|
|
|
original_filename "video.mp4"
|
|
|
|
width nil
|
|
|
|
height nil
|
|
|
|
thumbnail_width nil
|
|
|
|
thumbnail_height nil
|
|
|
|
extension "mp4"
|
|
|
|
end
|
|
|
|
|
2020-01-15 21:50:27 -06:00
|
|
|
Fabricator(:secure_upload, from: :upload) do
|
2020-04-22 13:49:53 -05:00
|
|
|
secure true
|
2020-01-15 21:50:27 -06:00
|
|
|
sha1 { SecureRandom.hex(20) }
|
|
|
|
original_sha1 { sequence(:sha1) { |n| Digest::SHA1.hexdigest(n.to_s) } }
|
|
|
|
end
|
|
|
|
|
2017-05-22 11:37:01 -05:00
|
|
|
Fabricator(:upload_s3, from: :upload) do
|
2018-09-14 00:42:59 -05:00
|
|
|
url do |attrs|
|
|
|
|
sequence(:url) do |n|
|
2019-05-30 01:38:46 -05:00
|
|
|
path = +Discourse.store.get_path_for(
|
|
|
|
"original", n + 1, attrs[:sha1], ".#{attrs[:extension]}"
|
2018-09-14 00:42:59 -05:00
|
|
|
)
|
2019-05-30 01:38:46 -05:00
|
|
|
|
|
|
|
if Rails.configuration.multisite
|
|
|
|
path.prepend(File.join(Discourse.store.upload_path, "/"))
|
|
|
|
end
|
|
|
|
|
|
|
|
File.join(Discourse.store.absolute_base_url, path)
|
2018-09-14 00:42:59 -05:00
|
|
|
end
|
|
|
|
end
|
2013-07-10 15:59:07 -05:00
|
|
|
end
|
2020-01-28 18:11:38 -06:00
|
|
|
|
2020-06-11 07:47:59 -05:00
|
|
|
Fabricator(:s3_image_upload, from: :upload_s3) do
|
|
|
|
after_create do |upload|
|
|
|
|
file = Tempfile.new(['fabricated', '.png'])
|
|
|
|
`convert -size #{upload.width}x#{upload.height} xc:white "#{file.path}"`
|
|
|
|
|
|
|
|
Discourse.store.store_upload(file, upload)
|
|
|
|
upload.sha1 = Upload.generate_digest(file.path)
|
|
|
|
|
|
|
|
WebMock
|
|
|
|
.stub_request(:get, upload.url)
|
|
|
|
.to_return(status: 200, body: File.new(file.path))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-01-28 18:11:38 -06:00
|
|
|
Fabricator(:secure_upload_s3, from: :upload_s3) do
|
2020-04-22 13:49:53 -05:00
|
|
|
secure true
|
2020-01-28 18:11:38 -06:00
|
|
|
sha1 { SecureRandom.hex(20) }
|
|
|
|
original_sha1 { sequence(:sha1) { |n| Digest::SHA1.hexdigest(n.to_s) } }
|
|
|
|
end
|