Files
nairobi/spec/lib/tasks/files_spec.rb
Javi Martín 5e7b3f72a2 Use File.exist? instead of File.exists?
We've noticed the following warning while testing the upgrade to
Ruby 3.0:

warning: File.exists? is deprecated; use File.exist? instead

We're adding a Rubocop rule so we don't call the deprecated method
in the future.
2023-01-26 17:21:19 +01:00

51 lines
1.5 KiB
Ruby

require "rails_helper"
describe "files tasks" do
describe "remove_old_cached_attachments" do
let(:run_rake_task) do
Rake::Task["files:remove_old_cached_attachments"].reenable
Rake.application.invoke_task("files:remove_old_cached_attachments")
end
it "deletes old cached attachments" do
image = build(:image)
document = build(:document)
image.attachment.blob.save!
image.attachment_changes["attachment"].upload
document.attachment.blob.save!
document.attachment_changes["attachment"].upload
travel_to(2.days.from_now) { run_rake_task }
expect(File.exist?(image.file_path)).to be false
expect(File.exist?(document.file_path)).to be false
end
it "does not delete recent cached attachments" do
image = build(:image)
document = build(:document)
image.attachment.blob.save!
image.attachment_changes["attachment"].upload
document.attachment.blob.save!
document.attachment_changes["attachment"].upload
travel_to(2.minutes.from_now) { run_rake_task }
expect(File.exist?(image.file_path)).to be true
expect(File.exist?(document.file_path)).to be true
end
it "does not delete old regular attachments" do
image = create(:image)
document = create(:document)
travel_to(2.days.from_now) { run_rake_task }
expect(File.exist?(image.file_path)).to be true
expect(File.exist?(document.file_path)).to be true
end
end
end