2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-03-18 11:25:15 -04:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
RSpec.describe Jobs::CleanUpInactiveUsers do
|
2019-03-18 21:53:18 -04:00
|
|
|
it "should clean up new users that have been inactive" do
|
|
|
|
SiteSetting.clean_up_inactive_users_after_days = 0
|
2019-03-18 11:25:15 -04:00
|
|
|
|
2019-03-18 21:53:18 -04:00
|
|
|
user = Fabricate(:user,
|
|
|
|
last_seen_at: 5.days.ago,
|
|
|
|
trust_level: TrustLevel.levels[:newuser]
|
|
|
|
)
|
2019-03-18 11:25:15 -04:00
|
|
|
|
2019-03-18 21:53:18 -04:00
|
|
|
Fabricate(:active_user)
|
|
|
|
|
|
|
|
Fabricate(:post, user: Fabricate(:user,
|
|
|
|
trust_level: TrustLevel.levels[:newuser],
|
|
|
|
last_seen_at: 5.days.ago
|
|
|
|
)).user
|
|
|
|
|
|
|
|
Fabricate(:user,
|
|
|
|
trust_level: TrustLevel.levels[:newuser],
|
|
|
|
last_seen_at: 2.days.ago
|
|
|
|
)
|
|
|
|
|
|
|
|
Fabricate(:user, trust_level: TrustLevel.levels[:basic])
|
|
|
|
|
|
|
|
expect { described_class.new.execute({}) }.to_not change { User.count }
|
2019-03-18 11:25:15 -04:00
|
|
|
|
2019-03-18 21:53:18 -04:00
|
|
|
SiteSetting.clean_up_inactive_users_after_days = 4
|
2019-03-18 11:25:15 -04:00
|
|
|
|
2019-03-18 21:53:18 -04:00
|
|
|
expect { described_class.new.execute({}) }
|
|
|
|
.to change { User.count }.by(-1)
|
2019-03-18 11:25:15 -04:00
|
|
|
|
2019-03-18 21:53:18 -04:00
|
|
|
expect(User.exists?(id: user.id)).to eq(false)
|
2019-03-18 11:25:15 -04:00
|
|
|
end
|
2019-04-25 05:59:31 -04:00
|
|
|
|
|
|
|
it "doesn't delete inactive admins" do
|
|
|
|
SiteSetting.clean_up_inactive_users_after_days = 4
|
|
|
|
admin = Fabricate(:admin, last_seen_at: 5.days.ago, trust_level: TrustLevel.levels[:newuser])
|
|
|
|
|
|
|
|
expect { described_class.new.execute({}) }.to_not change { User.count }
|
|
|
|
expect(User.exists?(admin.id)).to eq(true)
|
|
|
|
end
|
2019-05-13 15:44:03 -04:00
|
|
|
|
|
|
|
it "doesn't delete inactive mods" do
|
|
|
|
SiteSetting.clean_up_inactive_users_after_days = 4
|
|
|
|
moderator = Fabricate(:moderator, last_seen_at: 5.days.ago, trust_level: TrustLevel.levels[:newuser])
|
|
|
|
|
|
|
|
expect { described_class.new.execute({}) }.to_not change { User.count }
|
|
|
|
expect(User.exists?(moderator.id)).to eq(true)
|
|
|
|
end
|
2019-03-18 11:25:15 -04:00
|
|
|
end
|