feeds_vacuum_spec.rb 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe Vacuum::FeedsVacuum do
  4. subject { described_class.new }
  5. describe '#perform' do
  6. let!(:active_user) { Fabricate(:user, current_sign_in_at: 2.days.ago) }
  7. let!(:inactive_user) { Fabricate(:user, current_sign_in_at: 22.days.ago) }
  8. before do
  9. redis.zadd(feed_key_for(inactive_user), 1, 1)
  10. redis.zadd(feed_key_for(active_user), 1, 1)
  11. redis.zadd(feed_key_for(inactive_user, 'reblogs'), 2, 2)
  12. redis.sadd(feed_key_for(inactive_user, 'reblogs:2'), 3)
  13. end
  14. it 'clears feeds of inactive users and lists' do
  15. subject.perform
  16. expect(redis.zcard(feed_key_for(inactive_user))).to eq 0
  17. expect(redis.zcard(feed_key_for(active_user))).to eq 1
  18. expect(redis.exists?(feed_key_for(inactive_user, 'reblogs'))).to be false
  19. expect(redis.exists?(feed_key_for(inactive_user, 'reblogs:2'))).to be false
  20. end
  21. end
  22. def feed_key_for(user, subtype = nil)
  23. FeedManager.instance.key(:home, user.account_id, subtype)
  24. end
  25. end