mastodon/spec/workers/scheduler/feed_cleanup_scheduler_spec.rb
aschmitz 554c2fd8af Clean up reblog tracking keys, related improvements (#5428)
* Clean up reblog-tracking sets from FeedManager

Builds on #5419, with a few minor optimizations and cleanup of sets
after they are no longer needed.

* Update tests, fix multiply-reblogged case

Previously, we would have lost the fact that a given status was
reblogged if the displayed reblog of it was removed, now we don't.

Also added tests to make sure FeedManager#trim cleans up our reblog
tracking keys, fixed up FeedCleanupScheduler to use the right loop,
and fixed the test for it.
2017-10-17 11:45:06 +02:00

27 lines
991 B
Ruby

require 'rails_helper'
describe Scheduler::FeedCleanupScheduler do
subject { described_class.new }
let!(:active_user) { Fabricate(:user, current_sign_in_at: 2.days.ago) }
let!(:inactive_user) { Fabricate(:user, current_sign_in_at: 22.days.ago) }
it 'clears feeds of inactives' do
Redis.current.zadd(feed_key_for(inactive_user), 1, 1)
Redis.current.zadd(feed_key_for(active_user), 1, 1)
Redis.current.zadd(feed_key_for(inactive_user, 'reblogs'), 2, 2)
Redis.current.sadd(feed_key_for(inactive_user, 'reblogs:2'), 3)
subject.perform
expect(Redis.current.zcard(feed_key_for(inactive_user))).to eq 0
expect(Redis.current.zcard(feed_key_for(active_user))).to eq 1
expect(Redis.current.exists(feed_key_for(inactive_user, 'reblogs'))).to be false
expect(Redis.current.exists(feed_key_for(inactive_user, 'reblogs:2'))).to be false
end
def feed_key_for(user, subtype = nil)
FeedManager.instance.key(:home, user.account_id, subtype)
end
end