blob: 91c3efa9e6272d49b437a392031b92728b3d1f83 (
plain)
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
|
describe Workers::RemoveOldUser do
describe 'remove_old_users is active' do
before do
AppConfig.settings.maintenance.remove_old_users.enable = true
end
it '#removes user whose remove_after timestamp has passed' do
user = double(id: 1, remove_after: 1.day.ago, last_seen: 1000.days.ago)
allow(User).to receive(:find).with(user.id).and_return(user)
expect(user).to receive(:close_account!)
Workers::RemoveOldUser.new.perform(user.id)
end
it '#doesnt remove user whose remove_after timestamp hasnt passed' do
user = double(id: 1, remove_after: 1.day.from_now, last_seen: 1000.days.ago)
allow(User).to receive(:find).with(user.id).and_return(user)
expect(user).to_not receive(:close_account!)
Workers::RemoveOldUser.new.perform(user.id)
end
it '#doesnt remove user whose remove_after timestamp has passed but last_seen is recent' do
user = double(id: 1, remove_after: 1.day.ago, last_seen: 1.day.ago)
allow(User).to receive(:find).with(user.id).and_return(user)
expect(user).to_not receive(:close_account!)
Workers::RemoveOldUser.new.perform(user.id)
end
end
describe 'remove_old_users is inactive' do
before do
AppConfig.settings.maintenance.remove_old_users.enable = false
end
it '#doesnt remove user whose remove_after timestamp has passed' do
user = double(id: 1, remove_after: 1.day.ago, last_seen: 1000.days.ago)
allow(User).to receive(:find).with(user.id).and_return(user)
expect(user).to_not receive(:close_account!)
Workers::RemoveOldUser.new.perform(user.id)
end
it '#doesnt remove user whose remove_after timestamp hasnt passed' do
user = double(id: 1, remove_after: 1.day.from_now, last_seen: 1000.days.ago)
allow(User).to receive(:find).with(user.id).and_return(user)
expect(user).to_not receive(:close_account!)
Workers::RemoveOldUser.new.perform(user.id)
end
end
end
|