-
Notifications
You must be signed in to change notification settings - Fork 899
/
purging_spec.rb
40 lines (35 loc) · 1.56 KB
/
purging_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
describe Notification do
context "::Purging" do
describe ".purge_by_date" do
it "purges old notifications" do
FactoryGirl.create(:user)
FactoryGirl.create(:user)
type = FactoryGirl.create(:notification_type, :audience => NotificationType::AUDIENCE_GLOBAL)
# Notification and recipients that will not be purged
new_notification = FactoryGirl.create(:notification, :notification_type => type)
old_notification, semi_old_notification = nil
Timecop.freeze(6.days.ago) do
semi_old_notification = FactoryGirl.create(:notification, :notification_type => type)
end
Timecop.freeze(8.days.ago) do
# Notification and recipients that will be purged
old_notification = FactoryGirl.create(:notification, :notification_type => type)
end
expect(described_class.all).to match_array([new_notification, semi_old_notification, old_notification])
expect(NotificationRecipient.count).to eq(6)
count = described_class.purge_by_date(described_class.purge_date)
expect(described_class.all).to match_array([new_notification, semi_old_notification])
expect(NotificationRecipient.count).to eq(4)
expect(count).to eq(1)
end
end
describe ".purge_timer" do
it "queues the correct purge method" do
EvmSpecHelper.local_miq_server
described_class.purge_timer
q = MiqQueue.first
expect(q).to have_attributes(:class_name => described_class.name, :method_name => "purge_by_date")
end
end
end
end