discourse/spec/jobs/cleanup_imap_sync_log_spec.rb
David Taylor c9dab6fd08
DEV: Automatically require 'rails_helper' in all specs (#16077)
It's very easy to forget to add `require 'rails_helper'` at the top of every core/plugin spec file, and omissions can cause some very confusing/sporadic errors.

By setting this flag in `.rspec`, we can remove the need for `require 'rails_helper'` entirely.
2022-03-01 17:50:50 +00:00

24 lines
638 B
Ruby

# frozen_string_literal: true
describe Jobs::CleanupImapSyncLog do
let(:job_class) { Jobs::CleanupImapSyncLog.new }
it "deletes logs older than RETAIN_LOGS_DAYS" do
log1 = ImapSyncLog.log("Test log 1", :debug)
log2 = ImapSyncLog.log("Test log 2", :debug)
log3 = ImapSyncLog.log("Test log 3", :debug)
log2.update(created_at: 6.days.ago)
log3.update(created_at: 7.days.ago)
job_class.execute({})
expect(ImapSyncLog.count).to eq(1)
end
it "does not write the log to the db if specified" do
ImapSyncLog.debug("test", Fabricate(:group), db: false)
expect(ImapSyncLog.count).to eq(0)
end
end