2019-04-29 19:27:42 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-02-08 11:47:35 -06:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe Jobs::CleanUpEmailLogs do
|
2019-05-06 22:12:20 -05:00
|
|
|
fab!(:email_log) { Fabricate(:email_log, created_at: 2.years.ago) }
|
|
|
|
fab!(:email_log2) { Fabricate(:email_log, created_at: 2.weeks.ago) }
|
|
|
|
fab!(:email_log3) { Fabricate(:email_log, created_at: 2.days.ago) }
|
2016-02-08 11:47:35 -06:00
|
|
|
|
2018-10-07 22:11:00 -05:00
|
|
|
let!(:skipped_email_log) do
|
2018-07-23 23:55:43 -05:00
|
|
|
Fabricate(:skipped_email_log, created_at: 2.years.ago)
|
2016-02-08 11:47:35 -06:00
|
|
|
end
|
|
|
|
|
2019-05-06 22:12:20 -05:00
|
|
|
fab!(:skipped_email_log2) { Fabricate(:skipped_email_log) }
|
2018-10-07 22:11:00 -05:00
|
|
|
|
2018-07-26 23:32:07 -05:00
|
|
|
it "removes old email logs" do
|
2016-02-08 11:47:35 -06:00
|
|
|
Jobs::CleanUpEmailLogs.new.execute({})
|
2018-10-07 22:11:00 -05:00
|
|
|
expect(EmailLog.all).to contain_exactly(email_log2, email_log3)
|
|
|
|
expect(SkippedEmailLog.all).to contain_exactly(skipped_email_log2)
|
2016-02-08 11:47:35 -06:00
|
|
|
end
|
|
|
|
|
2016-02-08 15:18:52 -06:00
|
|
|
it "does not remove old email logs when delete_email_logs_after_days is 0" do
|
|
|
|
SiteSetting.delete_email_logs_after_days = 0
|
2016-02-08 11:47:35 -06:00
|
|
|
Jobs::CleanUpEmailLogs.new.execute({})
|
2018-10-07 22:11:00 -05:00
|
|
|
|
|
|
|
expect(EmailLog.all).to contain_exactly(email_log, email_log2, email_log3)
|
|
|
|
|
|
|
|
expect(SkippedEmailLog.all).to contain_exactly(
|
|
|
|
skipped_email_log,
|
|
|
|
skipped_email_log2
|
|
|
|
)
|
2016-02-08 11:47:35 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|