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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
require 'spec_helper'
describe Workers::QueueUsersForRemoval do
describe 'remove_old_users is active' do
before do
AppConfig.settings.maintenance.remove_old_users.enable = true
ActionMailer::Base.deliveries = nil
Timecop.freeze
end
it '#does not queue user that is not inactive' do
user = FactoryGirl.create(:user, :last_seen => Time.now-728.days, :sign_in_count => 5)
Workers::QueueUsersForRemoval.new.perform
user.reload
expect(user.remove_after).to eq(nil)
expect(ActionMailer::Base.deliveries.count).to eq(0)
end
it '#queues user that is inactive' do
removal_date = Time.now + (AppConfig.settings.maintenance.remove_old_users.warn_days.to_i).days
user = FactoryGirl.create(:user, :last_seen => Time.now-732.days, :sign_in_count => 5)
Workers::QueueUsersForRemoval.new.perform
user.reload
expect(user.remove_after.to_i).to eq(removal_date.utc.to_i)
expect(ActionMailer::Base.deliveries.count).to eq(1)
end
it '#queues user that is inactive and has not logged in' do
removal_date = Time.now
user = FactoryGirl.create(:user, :last_seen => Time.now-735.days, :sign_in_count => 0)
Workers::QueueUsersForRemoval.new.perform
user.reload
expect(user.remove_after.to_i).to eq(removal_date.utc.to_i)
expect(ActionMailer::Base.deliveries.count).to eq(0) # no email sent
end
it '#does not queue user that is not inactive and has not logged in' do
user = FactoryGirl.create(:user, :last_seen => Time.now-728.days, :sign_in_count => 0)
Workers::QueueUsersForRemoval.new.perform
user.reload
expect(user.remove_after).to eq(nil)
expect(ActionMailer::Base.deliveries.count).to eq(0)
end
it '#does not queue user that has already been flagged for removal' do
removal_date = Date.today + 5.days
user = FactoryGirl.create(:user, :last_seen => Time.now-735.days, :sign_in_count => 5, :remove_after => removal_date)
Workers::QueueUsersForRemoval.new.perform
user.reload
expect(user.remove_after).to eq(removal_date)
expect(ActionMailer::Base.deliveries.count).to eq(0)
end
after do
Timecop.return
end
end
describe 'remove_old_users is inactive' do
before do
AppConfig.settings.maintenance.remove_old_users.enable = false
ActionMailer::Base.deliveries = nil
end
it '#does not queue user that is not inactive' do
user = FactoryGirl.create(:user, :last_seen => Time.now-728.days, :sign_in_count => 5)
Workers::QueueUsersForRemoval.new.perform
user.reload
expect(user.remove_after).to eq(nil)
expect(ActionMailer::Base.deliveries.count).to eq(0)
end
it '#does not queue user that is inactive' do
user = FactoryGirl.create(:user, :last_seen => Time.now-735.days, :sign_in_count => 5)
Workers::QueueUsersForRemoval.new.perform
user.reload
expect(user.remove_after).to eq(nil)
expect(ActionMailer::Base.deliveries.count).to eq(0)
end
end
end
|