user_cleanup_scheduler_spec.rb 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. require 'rails_helper'
  2. describe Scheduler::UserCleanupScheduler do
  3. subject { described_class.new }
  4. let!(:new_unconfirmed_user) { Fabricate(:user) }
  5. let!(:old_unconfirmed_user) { Fabricate(:user) }
  6. let!(:confirmed_user) { Fabricate(:user) }
  7. let!(:moderation_note) { Fabricate(:account_moderation_note, account: Fabricate(:account), target_account: old_unconfirmed_user.account) }
  8. describe '#perform' do
  9. before do
  10. # Need to update the already-existing users because their initialization overrides confirmation_sent_at
  11. new_unconfirmed_user.update!(confirmed_at: nil, confirmation_sent_at: Time.now.utc)
  12. old_unconfirmed_user.update!(confirmed_at: nil, confirmation_sent_at: 1.week.ago)
  13. confirmed_user.update!(confirmed_at: 1.day.ago)
  14. end
  15. it 'deletes the old unconfirmed user' do
  16. expect { subject.perform }.to change { User.exists?(old_unconfirmed_user.id) }.from(true).to(false)
  17. end
  18. it "deletes the old unconfirmed user's account" do
  19. expect { subject.perform }.to change { Account.exists?(old_unconfirmed_user.account_id) }.from(true).to(false)
  20. end
  21. it 'does not delete the new unconfirmed user or their account' do
  22. subject.perform
  23. expect(User.exists?(new_unconfirmed_user.id)).to be true
  24. expect(Account.exists?(new_unconfirmed_user.account_id)).to be true
  25. end
  26. it 'does not delete the confirmed user or their account' do
  27. subject.perform
  28. expect(User.exists?(confirmed_user.id)).to be true
  29. expect(Account.exists?(confirmed_user.account_id)).to be true
  30. end
  31. end
  32. end