2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 22:27:38 -04:00
|
|
|
RSpec.describe Jobs::CleanUpUploads do
|
2018-06-04 22:03:26 -04:00
|
|
|
def fabricate_upload(attributes = {})
|
|
|
|
Fabricate(:upload, { created_at: 2.hours.ago }.merge(attributes))
|
2016-08-01 12:35:57 -04:00
|
|
|
end
|
|
|
|
|
2019-10-27 20:14:52 -04:00
|
|
|
fab! :expired_upload do
|
|
|
|
fabricate_upload
|
|
|
|
end
|
|
|
|
|
2016-06-20 16:05:41 -04:00
|
|
|
before do
|
2014-09-23 01:50:26 -04:00
|
|
|
SiteSetting.clean_up_uploads = true
|
2016-06-20 16:05:41 -04:00
|
|
|
SiteSetting.clean_orphan_uploads_grace_period_hours = 1
|
2019-10-27 20:14:52 -04:00
|
|
|
|
|
|
|
# pre-fabrication resets created_at, so re-expire the upload
|
|
|
|
expired_upload
|
|
|
|
freeze_time 2.hours.from_now
|
|
|
|
|
|
|
|
Jobs::CleanUpUploads.new.reset_last_cleanup!
|
|
|
|
end
|
|
|
|
|
|
|
|
it "only runs upload cleanup every grace period / 2 time" do
|
|
|
|
SiteSetting.clean_orphan_uploads_grace_period_hours = 48
|
|
|
|
expired = fabricate_upload(created_at: 49.hours.ago)
|
|
|
|
Jobs::CleanUpUploads.new.execute(nil)
|
|
|
|
|
|
|
|
expect(Upload.exists?(id: expired.id)).to eq(false)
|
|
|
|
|
|
|
|
upload = fabricate_upload(created_at: 72.hours.ago)
|
|
|
|
Jobs::CleanUpUploads.new.execute(nil)
|
|
|
|
|
|
|
|
expect(Upload.exists?(id: upload.id)).to eq(true)
|
|
|
|
|
|
|
|
freeze_time 25.hours.from_now
|
|
|
|
|
|
|
|
Jobs::CleanUpUploads.new.execute(nil)
|
|
|
|
expect(Upload.exists?(id: upload.id)).to eq(false)
|
2016-06-20 16:05:41 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "deletes orphan uploads" do
|
2018-06-04 22:03:26 -04:00
|
|
|
expect do Jobs::CleanUpUploads.new.execute(nil) end.to change { Upload.count }.by(-1)
|
2016-06-20 16:05:41 -04:00
|
|
|
|
2019-10-27 20:14:52 -04:00
|
|
|
expect(Upload.exists?(id: expired_upload.id)).to eq(false)
|
2018-06-04 22:03:26 -04:00
|
|
|
end
|
|
|
|
|
2022-02-16 02:00:30 -05:00
|
|
|
describe "unused callbacks" do
|
|
|
|
before { Upload.add_unused_callback { |uploads| uploads.where.not(id: expired_upload.id) } }
|
|
|
|
|
|
|
|
after { Upload.reset_unused_callbacks }
|
|
|
|
|
|
|
|
it "does not delete uploads skipped by an unused callback" do
|
|
|
|
expect do Jobs::CleanUpUploads.new.execute(nil) end.not_to change { Upload.count }
|
|
|
|
|
|
|
|
expect(Upload.exists?(id: expired_upload.id)).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "deletes other uploads not skipped by an unused callback" do
|
|
|
|
expired_upload2 = fabricate_upload
|
|
|
|
upload = fabricate_upload
|
2022-06-08 19:24:30 -04:00
|
|
|
UploadReference.create(target: Fabricate(:post), upload: upload)
|
2022-02-16 02:00:30 -05:00
|
|
|
|
|
|
|
expect do Jobs::CleanUpUploads.new.execute(nil) end.to change { Upload.count }.by(-1)
|
|
|
|
|
|
|
|
expect(Upload.exists?(id: expired_upload.id)).to eq(true)
|
|
|
|
expect(Upload.exists?(id: expired_upload2.id)).to eq(false)
|
|
|
|
expect(Upload.exists?(id: upload.id)).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "in use callbacks" do
|
|
|
|
before { Upload.add_in_use_callback { |upload| expired_upload.id == upload.id } }
|
|
|
|
|
|
|
|
after { Upload.reset_in_use_callbacks }
|
|
|
|
|
|
|
|
it "does not delete uploads that are in use by callback" do
|
|
|
|
expect do Jobs::CleanUpUploads.new.execute(nil) end.not_to change { Upload.count }
|
|
|
|
|
|
|
|
expect(Upload.exists?(id: expired_upload.id)).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "deletes other uploads that are not in use by callback" do
|
|
|
|
expired_upload2 = fabricate_upload
|
|
|
|
upload = fabricate_upload
|
2022-06-08 19:24:30 -04:00
|
|
|
UploadReference.create(target: Fabricate(:post), upload: upload)
|
2022-02-16 02:00:30 -05:00
|
|
|
|
|
|
|
expect do Jobs::CleanUpUploads.new.execute(nil) end.to change { Upload.count }.by(-1)
|
|
|
|
|
|
|
|
expect(Upload.exists?(id: expired_upload.id)).to eq(true)
|
|
|
|
expect(Upload.exists?(id: expired_upload2.id)).to eq(false)
|
|
|
|
expect(Upload.exists?(id: upload.id)).to eq(true)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-06-04 22:03:26 -04:00
|
|
|
describe "when clean_up_uploads is disabled" do
|
|
|
|
before { SiteSetting.clean_up_uploads = false }
|
|
|
|
|
|
|
|
it "should still delete invalid upload records" do
|
|
|
|
upload2 = fabricate_upload(url: "", retain_hours: nil)
|
|
|
|
|
|
|
|
expect do Jobs::CleanUpUploads.new.execute(nil) end.to change { Upload.count }.by(-1)
|
2016-06-20 16:05:41 -04:00
|
|
|
|
2019-10-27 20:14:52 -04:00
|
|
|
expect(Upload.exists?(id: expired_upload.id)).to eq(true)
|
2018-06-04 22:03:26 -04:00
|
|
|
expect(Upload.exists?(id: upload2.id)).to eq(false)
|
|
|
|
end
|
2014-09-23 01:50:26 -04:00
|
|
|
end
|
2016-06-20 16:05:41 -04:00
|
|
|
|
2018-11-14 02:03:02 -05:00
|
|
|
it "does not clean up upload site settings" do
|
|
|
|
begin
|
|
|
|
original_provider = SiteSetting.provider
|
|
|
|
SiteSetting.provider = SiteSettings::DbProvider.new(SiteSetting)
|
2018-11-29 21:46:39 -05:00
|
|
|
SiteSetting.clean_orphan_uploads_grace_period_hours = 1
|
2018-11-14 02:03:02 -05:00
|
|
|
|
2019-01-02 02:29:17 -05:00
|
|
|
system_upload = fabricate_upload(id: -999)
|
2018-11-14 02:03:02 -05:00
|
|
|
logo_upload = fabricate_upload
|
|
|
|
logo_small_upload = fabricate_upload
|
|
|
|
digest_logo_upload = fabricate_upload
|
|
|
|
mobile_logo_upload = fabricate_upload
|
|
|
|
large_icon_upload = fabricate_upload
|
|
|
|
opengraph_image_upload = fabricate_upload
|
|
|
|
twitter_summary_large_image_upload = fabricate_upload
|
|
|
|
favicon_upload = fabricate_upload
|
|
|
|
apple_touch_icon_upload = fabricate_upload
|
|
|
|
|
|
|
|
SiteSetting.logo = logo_upload
|
|
|
|
SiteSetting.logo_small = logo_small_upload
|
|
|
|
SiteSetting.digest_logo = digest_logo_upload
|
|
|
|
SiteSetting.mobile_logo = mobile_logo_upload
|
|
|
|
SiteSetting.large_icon = large_icon_upload
|
|
|
|
SiteSetting.opengraph_image = opengraph_image_upload
|
|
|
|
|
|
|
|
SiteSetting.twitter_summary_large_image = twitter_summary_large_image_upload
|
|
|
|
|
|
|
|
SiteSetting.favicon = favicon_upload
|
|
|
|
SiteSetting.apple_touch_icon = apple_touch_icon_upload
|
|
|
|
|
|
|
|
Jobs::CleanUpUploads.new.execute(nil)
|
|
|
|
|
|
|
|
[
|
2023-02-09 08:14:37 -05:00
|
|
|
logo_upload,
|
|
|
|
logo_small_upload,
|
|
|
|
digest_logo_upload,
|
|
|
|
mobile_logo_upload,
|
|
|
|
large_icon_upload,
|
|
|
|
opengraph_image_upload,
|
|
|
|
twitter_summary_large_image_upload,
|
|
|
|
favicon_upload,
|
|
|
|
apple_touch_icon_upload,
|
|
|
|
system_upload,
|
2018-11-14 02:03:02 -05:00
|
|
|
].each { |record| expect(Upload.exists?(id: record.id)).to eq(true) }
|
2018-11-29 21:46:39 -05:00
|
|
|
|
|
|
|
fabricate_upload
|
|
|
|
SiteSetting.opengraph_image = ""
|
|
|
|
|
|
|
|
Jobs::CleanUpUploads.new.execute(nil)
|
2018-11-14 02:03:02 -05:00
|
|
|
ensure
|
|
|
|
SiteSetting.delete_all
|
|
|
|
SiteSetting.provider = original_provider
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-10-13 09:17:06 -04:00
|
|
|
it "does not clean up selectable avatars" do
|
2022-06-08 19:24:30 -04:00
|
|
|
original_provider = SiteSetting.provider
|
|
|
|
SiteSetting.provider = SiteSettings::DbProvider.new(SiteSetting)
|
|
|
|
SiteSetting.clean_orphan_uploads_grace_period_hours = 1
|
|
|
|
|
2018-07-18 06:57:43 -04:00
|
|
|
avatar1_upload = fabricate_upload
|
|
|
|
avatar2_upload = fabricate_upload
|
|
|
|
|
2020-10-13 09:17:06 -04:00
|
|
|
SiteSetting.selectable_avatars = [avatar1_upload, avatar2_upload]
|
2016-09-08 16:58:07 -04:00
|
|
|
|
|
|
|
Jobs::CleanUpUploads.new.execute(nil)
|
|
|
|
|
2019-10-27 20:14:52 -04:00
|
|
|
expect(Upload.exists?(id: expired_upload.id)).to eq(false)
|
2018-07-18 06:57:43 -04:00
|
|
|
expect(Upload.exists?(id: avatar1_upload.id)).to eq(true)
|
|
|
|
expect(Upload.exists?(id: avatar2_upload.id)).to eq(true)
|
2022-06-08 19:24:30 -04:00
|
|
|
ensure
|
|
|
|
SiteSetting.delete_all
|
|
|
|
SiteSetting.provider = original_provider
|
2016-09-08 16:58:07 -04:00
|
|
|
end
|
|
|
|
|
2016-07-01 03:22:30 -04:00
|
|
|
it "does not delete profile background uploads" do
|
2016-08-01 12:35:57 -04:00
|
|
|
profile_background_upload = fabricate_upload
|
2019-04-28 23:58:52 -04:00
|
|
|
UserProfile.last.upload_profile_background(profile_background_upload)
|
2016-07-01 03:22:30 -04:00
|
|
|
|
|
|
|
Jobs::CleanUpUploads.new.execute(nil)
|
|
|
|
|
2019-10-27 20:14:52 -04:00
|
|
|
expect(Upload.exists?(id: expired_upload.id)).to eq(false)
|
2018-06-04 22:03:26 -04:00
|
|
|
expect(Upload.exists?(id: profile_background_upload.id)).to eq(true)
|
2016-07-01 03:22:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "does not delete card background uploads" do
|
2016-08-01 12:35:57 -04:00
|
|
|
card_background_upload = fabricate_upload
|
2019-04-28 23:58:52 -04:00
|
|
|
UserProfile.last.upload_card_background(card_background_upload)
|
2016-07-01 03:22:30 -04:00
|
|
|
|
|
|
|
Jobs::CleanUpUploads.new.execute(nil)
|
|
|
|
|
2019-10-27 20:14:52 -04:00
|
|
|
expect(Upload.exists?(id: expired_upload.id)).to eq(false)
|
2018-06-04 22:03:26 -04:00
|
|
|
expect(Upload.exists?(id: card_background_upload.id)).to eq(true)
|
2016-07-01 03:22:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "does not delete category logo uploads" do
|
2016-08-01 12:35:57 -04:00
|
|
|
category_logo_upload = fabricate_upload
|
2016-12-02 02:15:34 -05:00
|
|
|
Fabricate(:category, uploaded_logo: category_logo_upload)
|
2016-07-01 03:22:30 -04:00
|
|
|
|
|
|
|
Jobs::CleanUpUploads.new.execute(nil)
|
|
|
|
|
2019-10-27 20:14:52 -04:00
|
|
|
expect(Upload.exists?(id: expired_upload.id)).to eq(false)
|
2018-06-04 22:03:26 -04:00
|
|
|
expect(Upload.exists?(id: category_logo_upload.id)).to eq(true)
|
2016-07-01 03:22:30 -04:00
|
|
|
end
|
|
|
|
|
2022-10-07 11:00:44 -04:00
|
|
|
it "does not delete category dark logo uploads" do
|
|
|
|
category_logo_dark_upload = fabricate_upload
|
|
|
|
Fabricate(:category, uploaded_logo_dark: category_logo_dark_upload)
|
2016-07-01 03:22:30 -04:00
|
|
|
|
|
|
|
Jobs::CleanUpUploads.new.execute(nil)
|
|
|
|
|
2019-10-27 20:14:52 -04:00
|
|
|
expect(Upload.exists?(id: expired_upload.id)).to eq(false)
|
2022-10-07 11:00:44 -04:00
|
|
|
expect(Upload.exists?(id: category_logo_dark_upload.id)).to eq(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it "does not delete category background uploads" do
|
|
|
|
category_background_upload = fabricate_upload
|
|
|
|
Fabricate(:category, uploaded_background: category_background_upload)
|
|
|
|
|
|
|
|
Jobs::CleanUpUploads.new.execute(nil)
|
|
|
|
|
|
|
|
expect(Upload.exists?(id: expired_upload.id)).to eq(false)
|
|
|
|
expect(Upload.exists?(id: category_background_upload.id)).to eq(true)
|
2023-10-20 08:48:06 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "does not delete category dark background uploads" do
|
|
|
|
category_background_dark_upload = fabricate_upload
|
|
|
|
Fabricate(:category, uploaded_background_dark: category_background_dark_upload)
|
|
|
|
|
|
|
|
Jobs::CleanUpUploads.new.execute(nil)
|
|
|
|
|
|
|
|
expect(Upload.exists?(id: expired_upload.id)).to eq(false)
|
|
|
|
expect(Upload.exists?(id: category_background_dark_upload.id)).to eq(true)
|
2016-07-01 03:22:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "does not delete post uploads" do
|
2016-08-01 12:35:57 -04:00
|
|
|
upload = fabricate_upload
|
2016-09-08 16:58:07 -04:00
|
|
|
Fabricate(:post, uploads: [upload])
|
2016-07-01 03:22:30 -04:00
|
|
|
|
|
|
|
Jobs::CleanUpUploads.new.execute(nil)
|
|
|
|
|
2019-10-27 20:14:52 -04:00
|
|
|
expect(Upload.exists?(id: expired_upload.id)).to eq(false)
|
2018-06-04 22:03:26 -04:00
|
|
|
expect(Upload.exists?(id: upload.id)).to eq(true)
|
2016-07-01 03:22:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "does not delete user uploaded avatar" do
|
2016-08-01 12:35:57 -04:00
|
|
|
upload = fabricate_upload
|
2016-09-08 16:58:07 -04:00
|
|
|
Fabricate(:user, uploaded_avatar: upload)
|
2016-07-01 03:22:30 -04:00
|
|
|
|
|
|
|
Jobs::CleanUpUploads.new.execute(nil)
|
|
|
|
|
2019-10-27 20:14:52 -04:00
|
|
|
expect(Upload.exists?(id: expired_upload.id)).to eq(false)
|
2018-06-04 22:03:26 -04:00
|
|
|
expect(Upload.exists?(id: upload.id)).to eq(true)
|
2016-07-01 03:22:30 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "does not delete user gravatar" do
|
2016-08-01 12:35:57 -04:00
|
|
|
upload = fabricate_upload
|
2016-09-08 16:58:07 -04:00
|
|
|
Fabricate(:user, user_avatar: Fabricate(:user_avatar, gravatar_upload: upload))
|
2016-07-01 03:22:30 -04:00
|
|
|
|
|
|
|
Jobs::CleanUpUploads.new.execute(nil)
|
|
|
|
|
2019-10-27 20:14:52 -04:00
|
|
|
expect(Upload.exists?(id: expired_upload.id)).to eq(false)
|
2018-06-04 22:03:26 -04:00
|
|
|
expect(Upload.exists?(id: upload.id)).to eq(true)
|
2016-07-01 03:22:30 -04:00
|
|
|
end
|
2016-08-01 12:35:57 -04:00
|
|
|
|
2016-11-01 23:14:02 -04:00
|
|
|
it "does not delete user custom upload" do
|
|
|
|
upload = fabricate_upload
|
|
|
|
Fabricate(:user, user_avatar: Fabricate(:user_avatar, custom_upload: upload))
|
|
|
|
|
|
|
|
Jobs::CleanUpUploads.new.execute(nil)
|
|
|
|
|
2019-10-27 20:14:52 -04:00
|
|
|
expect(Upload.exists?(id: expired_upload.id)).to eq(false)
|
2018-06-04 22:03:26 -04:00
|
|
|
expect(Upload.exists?(id: upload.id)).to eq(true)
|
2016-11-01 23:14:02 -04:00
|
|
|
end
|
|
|
|
|
2016-08-01 12:35:57 -04:00
|
|
|
it "does not delete uploads in a queued post" do
|
|
|
|
upload = fabricate_upload
|
2017-11-13 09:01:31 -05:00
|
|
|
upload2 = fabricate_upload
|
2019-04-14 21:20:11 -04:00
|
|
|
upload3 = fabricate_upload
|
2016-08-01 12:35:57 -04:00
|
|
|
|
2019-04-14 21:20:11 -04:00
|
|
|
Fabricate(
|
|
|
|
:reviewable_queued_post_topic,
|
|
|
|
payload: {
|
2022-06-08 19:24:30 -04:00
|
|
|
raw: "#{upload.short_url}\n#{upload2.short_url}",
|
2019-04-14 21:20:11 -04:00
|
|
|
},
|
2023-11-19 18:50:09 -05:00
|
|
|
status: :pending,
|
2019-04-14 21:20:11 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
Fabricate(
|
|
|
|
:reviewable_queued_post_topic,
|
|
|
|
payload: {
|
2022-06-08 19:24:30 -04:00
|
|
|
raw: "#{upload3.short_url}",
|
2019-04-14 21:20:11 -04:00
|
|
|
},
|
2023-11-19 18:50:09 -05:00
|
|
|
status: :rejected,
|
2016-08-01 12:35:57 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
Jobs::CleanUpUploads.new.execute(nil)
|
|
|
|
|
2019-10-27 20:14:52 -04:00
|
|
|
expect(Upload.exists?(id: expired_upload.id)).to eq(false)
|
2018-06-04 22:03:26 -04:00
|
|
|
expect(Upload.exists?(id: upload.id)).to eq(true)
|
|
|
|
expect(Upload.exists?(id: upload2.id)).to eq(true)
|
2019-04-14 21:20:11 -04:00
|
|
|
expect(Upload.exists?(id: upload3.id)).to eq(false)
|
2016-08-01 12:35:57 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
it "does not delete uploads in a draft" do
|
|
|
|
upload = fabricate_upload
|
2017-11-13 09:01:31 -05:00
|
|
|
upload2 = fabricate_upload
|
|
|
|
|
2022-06-08 19:24:30 -04:00
|
|
|
Draft.set(Fabricate(:user), "test", 0, "upload://#{upload.sha1}\n#{upload2.short_url}")
|
2016-08-01 12:35:57 -04:00
|
|
|
|
|
|
|
Jobs::CleanUpUploads.new.execute(nil)
|
|
|
|
|
2019-10-27 20:14:52 -04:00
|
|
|
expect(Upload.exists?(id: expired_upload.id)).to eq(false)
|
2018-06-04 22:03:26 -04:00
|
|
|
expect(Upload.exists?(id: upload.id)).to eq(true)
|
|
|
|
expect(Upload.exists?(id: upload2.id)).to eq(true)
|
2016-08-01 12:35:57 -04:00
|
|
|
end
|
|
|
|
|
2020-01-15 22:50:27 -05:00
|
|
|
it "does not delete uploads with an access control post ID (secure uploads)" do
|
|
|
|
upload = fabricate_upload(access_control_post_id: Fabricate(:post).id, secure: true)
|
|
|
|
|
|
|
|
Jobs::CleanUpUploads.new.execute(nil)
|
|
|
|
|
|
|
|
expect(Upload.exists?(id: expired_upload.id)).to eq(false)
|
|
|
|
expect(Upload.exists?(id: upload.id)).to eq(true)
|
|
|
|
end
|
|
|
|
|
2017-02-02 04:41:57 -05:00
|
|
|
it "does not delete custom emojis" do
|
|
|
|
upload = fabricate_upload
|
|
|
|
CustomEmoji.create!(name: "test", upload: upload)
|
|
|
|
|
|
|
|
Jobs::CleanUpUploads.new.execute(nil)
|
|
|
|
|
2019-10-27 20:14:52 -04:00
|
|
|
expect(Upload.exists?(id: expired_upload.id)).to eq(false)
|
2018-06-04 22:03:26 -04:00
|
|
|
expect(Upload.exists?(id: upload.id)).to eq(true)
|
2017-02-02 04:41:57 -05:00
|
|
|
end
|
|
|
|
|
2018-04-19 07:30:31 -04:00
|
|
|
it "does not delete user exported csv uploads" do
|
|
|
|
csv_file = fabricate_upload
|
|
|
|
UserExport.create(file_name: "export.csv", user_id: Fabricate(:user).id, upload_id: csv_file.id)
|
|
|
|
|
|
|
|
Jobs::CleanUpUploads.new.execute(nil)
|
|
|
|
|
2019-10-27 20:14:52 -04:00
|
|
|
expect(Upload.exists?(id: expired_upload.id)).to eq(false)
|
2018-06-04 22:03:26 -04:00
|
|
|
expect(Upload.exists?(id: csv_file.id)).to eq(true)
|
2018-04-19 07:30:31 -04:00
|
|
|
end
|
2021-03-09 14:16:45 -05:00
|
|
|
|
|
|
|
it "does not delete theme setting uploads" do
|
|
|
|
theme = Fabricate(:theme)
|
|
|
|
theme_upload = fabricate_upload
|
2021-09-15 22:28:53 -04:00
|
|
|
ThemeSetting.create!(
|
|
|
|
theme: theme,
|
|
|
|
data_type: ThemeSetting.types[:upload],
|
|
|
|
value: theme_upload.id.to_s,
|
|
|
|
name: "my_setting_name",
|
|
|
|
)
|
2021-03-09 14:16:45 -05:00
|
|
|
|
|
|
|
Jobs::CleanUpUploads.new.execute(nil)
|
|
|
|
|
|
|
|
expect(Upload.exists?(id: expired_upload.id)).to eq(false)
|
|
|
|
expect(Upload.exists?(id: theme_upload.id)).to eq(true)
|
|
|
|
end
|
2021-03-17 01:55:23 -04:00
|
|
|
|
|
|
|
it "does not delete badges uploads" do
|
|
|
|
badge_image = fabricate_upload
|
|
|
|
badge = Fabricate(:badge, image_upload_id: badge_image.id)
|
|
|
|
|
|
|
|
Jobs::CleanUpUploads.new.execute(nil)
|
|
|
|
|
|
|
|
expect(Upload.exists?(id: expired_upload.id)).to eq(false)
|
|
|
|
expect(Upload.exists?(id: badge_image.id)).to eq(true)
|
|
|
|
end
|
2021-07-27 18:42:25 -04:00
|
|
|
|
|
|
|
it "deletes external upload stubs that have expired" do
|
|
|
|
external_stub1 =
|
|
|
|
Fabricate(
|
|
|
|
:external_upload_stub,
|
|
|
|
status: ExternalUploadStub.statuses[:created],
|
|
|
|
created_at: 10.minutes.ago,
|
|
|
|
)
|
|
|
|
external_stub2 =
|
|
|
|
Fabricate(
|
|
|
|
:external_upload_stub,
|
|
|
|
status: ExternalUploadStub.statuses[:created],
|
|
|
|
created_at: (ExternalUploadStub::CREATED_EXPIRY_HOURS.hours + 10.minutes).ago,
|
|
|
|
)
|
|
|
|
external_stub3 =
|
|
|
|
Fabricate(
|
|
|
|
:external_upload_stub,
|
|
|
|
status: ExternalUploadStub.statuses[:uploaded],
|
|
|
|
created_at: 10.minutes.ago,
|
|
|
|
)
|
|
|
|
external_stub4 =
|
|
|
|
Fabricate(
|
|
|
|
:external_upload_stub,
|
|
|
|
status: ExternalUploadStub.statuses[:uploaded],
|
|
|
|
created_at: (ExternalUploadStub::UPLOADED_EXPIRY_HOURS.hours + 10.minutes).ago,
|
|
|
|
)
|
|
|
|
Jobs::CleanUpUploads.new.execute(nil)
|
|
|
|
expect(ExternalUploadStub.pluck(:id)).to contain_exactly(external_stub1.id, external_stub3.id)
|
|
|
|
end
|
2024-08-29 20:25:04 -04:00
|
|
|
|
|
|
|
it "does not delete create external upload stubs for 2 days if debug mode is on" do
|
|
|
|
SiteSetting.enable_upload_debug_mode = true
|
|
|
|
external_stub1 =
|
|
|
|
Fabricate(
|
|
|
|
:external_upload_stub,
|
|
|
|
status: ExternalUploadStub.statuses[:created],
|
|
|
|
created_at: 2.hours.ago,
|
|
|
|
)
|
|
|
|
Jobs::CleanUpUploads.new.execute(nil)
|
|
|
|
expect(ExternalUploadStub.pluck(:id)).to contain_exactly(external_stub1.id)
|
|
|
|
|
|
|
|
SiteSetting.enable_upload_debug_mode = false
|
|
|
|
Jobs::CleanUpUploads.new.execute(nil)
|
|
|
|
expect(ExternalUploadStub.pluck(:id)).to be_empty
|
|
|
|
end
|
2014-09-23 01:50:26 -04:00
|
|
|
end
|