diff options
Diffstat (limited to 'spec/lib/feed_manager_spec.rb')
-rw-r--r-- | spec/lib/feed_manager_spec.rb | 111 |
1 files changed, 97 insertions, 14 deletions
diff --git a/spec/lib/feed_manager_spec.rb b/spec/lib/feed_manager_spec.rb index 923894ccb..0f97a579e 100644 --- a/spec/lib/feed_manager_spec.rb +++ b/spec/lib/feed_manager_spec.rb @@ -211,6 +211,22 @@ RSpec.describe FeedManager do expect(FeedManager.instance.push('type', account, reblogs.last)).to be false end + it 'does not save a new reblog of a multiply-reblogged-then-unreblogged status' do + account = Fabricate(:account) + reblogged = Fabricate(:status) + reblogs = 3.times.map { Fabricate(:status, reblog: reblogged) } + + # Accept the reblogs + FeedManager.instance.push('type', account, reblogs[0]) + FeedManager.instance.push('type', account, reblogs[1]) + + # Unreblog the first one + FeedManager.instance.unpush('type', account, reblogs[0]) + + # The last reblog should still be ignored + expect(FeedManager.instance.push('type', account, reblogs.last)).to be false + end + it 'saves a new reblog of a long-ago-reblogged status' do account = Fabricate(:account) reblogged = Fabricate(:status) @@ -230,34 +246,101 @@ RSpec.describe FeedManager do end end + describe '#trim' do + let(:receiver) { Fabricate(:account) } + + it 'cleans up reblog tracking keys' do + reblogged = Fabricate(:status) + status = Fabricate(:status, reblog: reblogged) + another_status = Fabricate(:status, reblog: reblogged) + reblogs_key = FeedManager.instance.key('type', receiver.id, 'reblogs') + reblog_set_key = FeedManager.instance.key('type', receiver.id, "reblogs:#{reblogged.id}") + + FeedManager.instance.push('type', receiver, status) + FeedManager.instance.push('type', receiver, another_status) + + # We should have a tracking set and an entry in reblogs. + expect(Redis.current.exists(reblog_set_key)).to be true + expect(Redis.current.zrange(reblogs_key, 0, -1)).to eq [reblogged.id.to_s] + + # Push everything off the end of the feed. + FeedManager::MAX_ITEMS.times do + FeedManager.instance.push('type', receiver, Fabricate(:status)) + end + + # `trim` should be called automatically, but do it anyway, as + # we're testing `trim`, not side effects of `push`. + FeedManager.instance.trim('type', receiver.id) + + # We should not have any reblog tracking data. + expect(Redis.current.exists(reblog_set_key)).to be false + expect(Redis.current.zrange(reblogs_key, 0, -1)).to be_empty + end + end + describe '#unpush' do - it 'leaves a reblogged status when deleting the reblog' do - account = Fabricate(:account) + let(:receiver) { Fabricate(:account) } + + it 'leaves a reblogged status if original was on feed' do reblogged = Fabricate(:status) - status = Fabricate(:status, reblog: reblogged) + status = Fabricate(:status, reblog: reblogged) - FeedManager.instance.push('type', account, status) + FeedManager.instance.push('type', receiver, reblogged) + FeedManager::REBLOG_FALLOFF.times { FeedManager.instance.push('type', receiver, Fabricate(:status)) } + FeedManager.instance.push('type', receiver, status) + + # The reblogging status should show up under normal conditions. + expect(Redis.current.zrange("feed:type:#{receiver.id}", 0, -1)).to include(status.id.to_s) + + FeedManager.instance.unpush('type', receiver, status) + + # Restore original status + expect(Redis.current.zrange("feed:type:#{receiver.id}", 0, -1)).to_not include(status.id.to_s) + expect(Redis.current.zrange("feed:type:#{receiver.id}", 0, -1)).to include(reblogged.id.to_s) + end + + it 'removes a reblogged status if it was only reblogged once' do + reblogged = Fabricate(:status) + status = Fabricate(:status, reblog: reblogged) + + FeedManager.instance.push('type', receiver, status) # The reblogging status should show up under normal conditions. - expect(Redis.current.zrange("feed:type:#{account.id}", 0, -1)).to eq [status.id.to_s] + expect(Redis.current.zrange("feed:type:#{receiver.id}", 0, -1)).to eq [status.id.to_s] - FeedManager.instance.unpush('type', account, status) + FeedManager.instance.unpush('type', receiver, status) - # Because we couldn't tell if the status showed up any other way, - # we had to stick the reblogged status in by itself. - expect(Redis.current.zrange("feed:type:#{account.id}", 0, -1)).to eq [reblogged.id.to_s] + expect(Redis.current.zrange("feed:type:#{receiver.id}", 0, -1)).to be_empty + end + + it 'leaves a multiply-reblogged status if another reblog was in feed' do + reblogged = Fabricate(:status) + reblogs = 3.times.map { Fabricate(:status, reblog: reblogged) } + + reblogs.each do |reblog| + FeedManager.instance.push('type', receiver, reblog) + end + + # The reblogging status should show up under normal conditions. + expect(Redis.current.zrange("feed:type:#{receiver.id}", 0, -1)).to eq [reblogs.first.id.to_s] + + reblogs[0...-1].each do |reblog| + FeedManager.instance.unpush('type', receiver, reblog) + end + + expect(Redis.current.zrange("feed:type:#{receiver.id}", 0, -1)).to eq [reblogs.last.id.to_s] end it 'sends push updates' do - account = Fabricate(:account) - status = Fabricate(:status) - FeedManager.instance.push('type', account, status) + status = Fabricate(:status) + + FeedManager.instance.push('type', receiver, status) allow(Redis.current).to receive_messages(publish: nil) - FeedManager.instance.unpush('type', account, status) + FeedManager.instance.unpush('type', receiver, status) deletion = Oj.dump(event: :delete, payload: status.id.to_s) - expect(Redis.current).to have_received(:publish).with("timeline:#{account.id}", deletion) + expect(Redis.current).to have_received(:publish).with("timeline:#{receiver.id}", deletion) end end end |