2019-07-07 11:18:12 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-09-29 09:46:39 +05:30
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe PruneOldEventsWorker do
|
|
|
|
describe '#perform' do
|
2017-09-10 17:25:29 +05:30
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
let!(:expired_event) { create(:event, :closed, author: user, created_at: 25.months.ago) }
|
2019-03-02 22:35:43 +05:30
|
|
|
let!(:not_expired_1_day_event) { create(:event, :closed, author: user, created_at: 1.day.ago) }
|
|
|
|
let!(:not_expired_13_month_event) { create(:event, :closed, author: user, created_at: 13.months.ago) }
|
2018-12-05 23:21:45 +05:30
|
|
|
let!(:not_expired_2_years_event) { create(:event, :closed, author: user, created_at: 2.years.ago) }
|
2016-09-29 09:46:39 +05:30
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
it 'prunes events older than 2 years' do
|
2016-09-29 09:46:39 +05:30
|
|
|
expect { subject.perform }.to change { Event.count }.by(-1)
|
|
|
|
expect(Event.find_by(id: expired_event.id)).to be_nil
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'leaves fresh events' do
|
|
|
|
subject.perform
|
2018-12-05 23:21:45 +05:30
|
|
|
expect(not_expired_1_day_event.reload).to be_present
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
it 'leaves events from 13 months ago' do
|
2016-09-29 09:46:39 +05:30
|
|
|
subject.perform
|
2018-12-05 23:21:45 +05:30
|
|
|
expect(not_expired_13_month_event.reload).to be_present
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'leaves events from 2 years ago' do
|
|
|
|
subject.perform
|
|
|
|
expect(not_expired_2_years_event).to be_present
|
2016-09-29 09:46:39 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|