From df4e79b842fa16b370c8c4b07b82bdd328f3ef7e Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Tue, 2 Jul 2019 02:37:02 +0200 Subject: Cleanup pending photos which were never posted with cronjob Only delete photos older than a day, so we don't delete photos for posts which were uploaded 10 minutes ago and the author is still writing the post for it. closes #8041 --- spec/workers/cleanup_pending_photos_spec.rb | 31 +++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 spec/workers/cleanup_pending_photos_spec.rb (limited to 'spec/workers') diff --git a/spec/workers/cleanup_pending_photos_spec.rb b/spec/workers/cleanup_pending_photos_spec.rb new file mode 100644 index 000000000..1a92cac96 --- /dev/null +++ b/spec/workers/cleanup_pending_photos_spec.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +describe Workers::CleanupPendingPhotos do + let!(:photo) { FactoryGirl.create(:photo, author: alice.person, pending: true) } + + it "removes pending photos" do + Timecop.travel(25.hours) do + Workers::CleanupPendingPhotos.new.perform + expect(Photo).not_to exist(photo.id) + end + end + + it "does not remove pending photos newer than one day" do + Timecop.travel(1.hour) do + Workers::CleanupPendingPhotos.new.perform + expect(Photo).to exist(photo.id) + end + end + + it "does not remove posted photos" do + StatusMessageCreationService.new(alice).create( + status_message: {text: "Post with photo"}, + public: true, + photos: [photo.id] + ) + Timecop.travel(25.hours) do + Workers::CleanupPendingPhotos.new.perform + expect(Photo).to exist(photo.id) + end + end +end -- cgit v1.2.3