|
|
@ -207,21 +207,11 @@ RSpec.describe FeedManager do |
|
|
|
account = Fabricate(:account) |
|
|
|
account = Fabricate(:account) |
|
|
|
status = Fabricate(:status) |
|
|
|
status = Fabricate(:status) |
|
|
|
members = FeedManager::MAX_ITEMS.times.map { |count| [count, count] } |
|
|
|
members = FeedManager::MAX_ITEMS.times.map { |count| [count, count] } |
|
|
|
Redis.current.zadd("feed:type:#{account.id}", members) |
|
|
|
Redis.current.zadd("feed:home:#{account.id}", members) |
|
|
|
|
|
|
|
|
|
|
|
FeedManager.instance.push('type', account, status) |
|
|
|
FeedManager.instance.push_to_home(account, status) |
|
|
|
|
|
|
|
|
|
|
|
expect(Redis.current.zcard("feed:type:#{account.id}")).to eq FeedManager::MAX_ITEMS |
|
|
|
expect(Redis.current.zcard("feed:home:#{account.id}")).to eq FeedManager::MAX_ITEMS |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
it 'sends push updates for non-home timelines' do |
|
|
|
|
|
|
|
account = Fabricate(:account) |
|
|
|
|
|
|
|
status = Fabricate(:status) |
|
|
|
|
|
|
|
allow(Redis.current).to receive_messages(publish: nil) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FeedManager.instance.push('type', account, status) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
expect(Redis.current).to have_received(:publish).with("timeline:#{account.id}", any_args).at_least(:once) |
|
|
|
|
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
context 'reblogs' do |
|
|
|
context 'reblogs' do |
|
|
@ -230,7 +220,7 @@ RSpec.describe FeedManager do |
|
|
|
reblogged = Fabricate(:status) |
|
|
|
reblogged = Fabricate(:status) |
|
|
|
reblog = Fabricate(:status, reblog: reblogged) |
|
|
|
reblog = Fabricate(:status, reblog: reblogged) |
|
|
|
|
|
|
|
|
|
|
|
expect(FeedManager.instance.push('type', account, reblog)).to be true |
|
|
|
expect(FeedManager.instance.push_to_home(account, reblog)).to be true |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it 'does not save a new reblog of a recent status' do |
|
|
|
it 'does not save a new reblog of a recent status' do |
|
|
@ -238,9 +228,9 @@ RSpec.describe FeedManager do |
|
|
|
reblogged = Fabricate(:status) |
|
|
|
reblogged = Fabricate(:status) |
|
|
|
reblog = Fabricate(:status, reblog: reblogged) |
|
|
|
reblog = Fabricate(:status, reblog: reblogged) |
|
|
|
|
|
|
|
|
|
|
|
FeedManager.instance.push('type', account, reblogged) |
|
|
|
FeedManager.instance.push_to_home(account, reblogged) |
|
|
|
|
|
|
|
|
|
|
|
expect(FeedManager.instance.push('type', account, reblog)).to be false |
|
|
|
expect(FeedManager.instance.push_to_home(account, reblog)).to be false |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it 'saves a new reblog of an old status' do |
|
|
|
it 'saves a new reblog of an old status' do |
|
|
@ -248,14 +238,14 @@ RSpec.describe FeedManager do |
|
|
|
reblogged = Fabricate(:status) |
|
|
|
reblogged = Fabricate(:status) |
|
|
|
reblog = Fabricate(:status, reblog: reblogged) |
|
|
|
reblog = Fabricate(:status, reblog: reblogged) |
|
|
|
|
|
|
|
|
|
|
|
FeedManager.instance.push('type', account, reblogged) |
|
|
|
FeedManager.instance.push_to_home(account, reblogged) |
|
|
|
|
|
|
|
|
|
|
|
# Fill the feed with intervening statuses |
|
|
|
# Fill the feed with intervening statuses |
|
|
|
FeedManager::REBLOG_FALLOFF.times do |
|
|
|
FeedManager::REBLOG_FALLOFF.times do |
|
|
|
FeedManager.instance.push('type', account, Fabricate(:status)) |
|
|
|
FeedManager.instance.push_to_home(account, Fabricate(:status)) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
expect(FeedManager.instance.push('type', account, reblog)).to be true |
|
|
|
expect(FeedManager.instance.push_to_home(account, reblog)).to be true |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it 'does not save a new reblog of a recently-reblogged status' do |
|
|
|
it 'does not save a new reblog of a recently-reblogged status' do |
|
|
@ -264,10 +254,10 @@ RSpec.describe FeedManager do |
|
|
|
reblogs = 2.times.map { Fabricate(:status, reblog: reblogged) } |
|
|
|
reblogs = 2.times.map { Fabricate(:status, reblog: reblogged) } |
|
|
|
|
|
|
|
|
|
|
|
# The first reblog will be accepted |
|
|
|
# The first reblog will be accepted |
|
|
|
FeedManager.instance.push('type', account, reblogs.first) |
|
|
|
FeedManager.instance.push_to_home(account, reblogs.first) |
|
|
|
|
|
|
|
|
|
|
|
# The second reblog should be ignored |
|
|
|
# The second reblog should be ignored |
|
|
|
expect(FeedManager.instance.push('type', account, reblogs.last)).to be false |
|
|
|
expect(FeedManager.instance.push_to_home(account, reblogs.last)).to be false |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it 'does not save a new reblog of a multiply-reblogged-then-unreblogged status' do |
|
|
|
it 'does not save a new reblog of a multiply-reblogged-then-unreblogged status' do |
|
|
@ -276,14 +266,14 @@ RSpec.describe FeedManager do |
|
|
|
reblogs = 3.times.map { Fabricate(:status, reblog: reblogged) } |
|
|
|
reblogs = 3.times.map { Fabricate(:status, reblog: reblogged) } |
|
|
|
|
|
|
|
|
|
|
|
# Accept the reblogs |
|
|
|
# Accept the reblogs |
|
|
|
FeedManager.instance.push('type', account, reblogs[0]) |
|
|
|
FeedManager.instance.push_to_home(account, reblogs[0]) |
|
|
|
FeedManager.instance.push('type', account, reblogs[1]) |
|
|
|
FeedManager.instance.push_to_home(account, reblogs[1]) |
|
|
|
|
|
|
|
|
|
|
|
# Unreblog the first one |
|
|
|
# Unreblog the first one |
|
|
|
FeedManager.instance.unpush('type', account, reblogs[0]) |
|
|
|
FeedManager.instance.unpush_from_home(account, reblogs[0]) |
|
|
|
|
|
|
|
|
|
|
|
# The last reblog should still be ignored |
|
|
|
# The last reblog should still be ignored |
|
|
|
expect(FeedManager.instance.push('type', account, reblogs.last)).to be false |
|
|
|
expect(FeedManager.instance.push_to_home(account, reblogs.last)).to be false |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it 'saves a new reblog of a long-ago-reblogged status' do |
|
|
|
it 'saves a new reblog of a long-ago-reblogged status' do |
|
|
@ -292,15 +282,15 @@ RSpec.describe FeedManager do |
|
|
|
reblogs = 2.times.map { Fabricate(:status, reblog: reblogged) } |
|
|
|
reblogs = 2.times.map { Fabricate(:status, reblog: reblogged) } |
|
|
|
|
|
|
|
|
|
|
|
# The first reblog will be accepted |
|
|
|
# The first reblog will be accepted |
|
|
|
FeedManager.instance.push('type', account, reblogs.first) |
|
|
|
FeedManager.instance.push_to_home(account, reblogs.first) |
|
|
|
|
|
|
|
|
|
|
|
# Fill the feed with intervening statuses |
|
|
|
# Fill the feed with intervening statuses |
|
|
|
FeedManager::REBLOG_FALLOFF.times do |
|
|
|
FeedManager::REBLOG_FALLOFF.times do |
|
|
|
FeedManager.instance.push('type', account, Fabricate(:status)) |
|
|
|
FeedManager.instance.push_to_home(account, Fabricate(:status)) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
# The second reblog should also be accepted |
|
|
|
# The second reblog should also be accepted |
|
|
|
expect(FeedManager.instance.push('type', account, reblogs.last)).to be true |
|
|
|
expect(FeedManager.instance.push_to_home(account, reblogs.last)).to be true |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
|
end |
|
|
@ -312,11 +302,11 @@ RSpec.describe FeedManager do |
|
|
|
reblogged = Fabricate(:status) |
|
|
|
reblogged = Fabricate(:status) |
|
|
|
status = Fabricate(:status, reblog: reblogged) |
|
|
|
status = Fabricate(:status, reblog: reblogged) |
|
|
|
another_status = Fabricate(:status, reblog: reblogged) |
|
|
|
another_status = Fabricate(:status, reblog: reblogged) |
|
|
|
reblogs_key = FeedManager.instance.key('type', receiver.id, 'reblogs') |
|
|
|
reblogs_key = FeedManager.instance.key('home', receiver.id, 'reblogs') |
|
|
|
reblog_set_key = FeedManager.instance.key('type', receiver.id, "reblogs:#{reblogged.id}") |
|
|
|
reblog_set_key = FeedManager.instance.key('home', receiver.id, "reblogs:#{reblogged.id}") |
|
|
|
|
|
|
|
|
|
|
|
FeedManager.instance.push('type', receiver, status) |
|
|
|
FeedManager.instance.push_to_home(receiver, status) |
|
|
|
FeedManager.instance.push('type', receiver, another_status) |
|
|
|
FeedManager.instance.push_to_home(receiver, another_status) |
|
|
|
|
|
|
|
|
|
|
|
# We should have a tracking set and an entry in reblogs. |
|
|
|
# We should have a tracking set and an entry in reblogs. |
|
|
|
expect(Redis.current.exists(reblog_set_key)).to be true |
|
|
|
expect(Redis.current.exists(reblog_set_key)).to be true |
|
|
@ -324,12 +314,12 @@ RSpec.describe FeedManager do |
|
|
|
|
|
|
|
|
|
|
|
# Push everything off the end of the feed. |
|
|
|
# Push everything off the end of the feed. |
|
|
|
FeedManager::MAX_ITEMS.times do |
|
|
|
FeedManager::MAX_ITEMS.times do |
|
|
|
FeedManager.instance.push('type', receiver, Fabricate(:status)) |
|
|
|
FeedManager.instance.push_to_home(receiver, Fabricate(:status)) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
# `trim` should be called automatically, but do it anyway, as |
|
|
|
# `trim` should be called automatically, but do it anyway, as |
|
|
|
# we're testing `trim`, not side effects of `push`. |
|
|
|
# we're testing `trim`, not side effects of `push`. |
|
|
|
FeedManager.instance.trim('type', receiver.id) |
|
|
|
FeedManager.instance.trim('home', receiver.id) |
|
|
|
|
|
|
|
|
|
|
|
# We should not have any reblog tracking data. |
|
|
|
# We should not have any reblog tracking data. |
|
|
|
expect(Redis.current.exists(reblog_set_key)).to be false |
|
|
|
expect(Redis.current.exists(reblog_set_key)).to be false |
|
|
@ -344,32 +334,32 @@ RSpec.describe FeedManager do |
|
|
|
reblogged = Fabricate(:status) |
|
|
|
reblogged = Fabricate(:status) |
|
|
|
status = Fabricate(:status, reblog: reblogged) |
|
|
|
status = Fabricate(:status, reblog: reblogged) |
|
|
|
|
|
|
|
|
|
|
|
FeedManager.instance.push('type', receiver, reblogged) |
|
|
|
FeedManager.instance.push_to_home(receiver, reblogged) |
|
|
|
FeedManager::REBLOG_FALLOFF.times { FeedManager.instance.push('type', receiver, Fabricate(:status)) } |
|
|
|
FeedManager::REBLOG_FALLOFF.times { FeedManager.instance.push_to_home(receiver, Fabricate(:status)) } |
|
|
|
FeedManager.instance.push('type', receiver, status) |
|
|
|
FeedManager.instance.push_to_home(receiver, status) |
|
|
|
|
|
|
|
|
|
|
|
# The reblogging status should show up under normal conditions. |
|
|
|
# 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) |
|
|
|
expect(Redis.current.zrange("feed:home:#{receiver.id}", 0, -1)).to include(status.id.to_s) |
|
|
|
|
|
|
|
|
|
|
|
FeedManager.instance.unpush('type', receiver, status) |
|
|
|
FeedManager.instance.unpush_from_home(receiver, status) |
|
|
|
|
|
|
|
|
|
|
|
# Restore original 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:home:#{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) |
|
|
|
expect(Redis.current.zrange("feed:home:#{receiver.id}", 0, -1)).to include(reblogged.id.to_s) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it 'removes a reblogged status if it was only reblogged once' do |
|
|
|
it 'removes a reblogged status if it was only reblogged once' do |
|
|
|
reblogged = Fabricate(:status) |
|
|
|
reblogged = Fabricate(:status) |
|
|
|
status = Fabricate(:status, reblog: reblogged) |
|
|
|
status = Fabricate(:status, reblog: reblogged) |
|
|
|
|
|
|
|
|
|
|
|
FeedManager.instance.push('type', receiver, status) |
|
|
|
FeedManager.instance.push_to_home(receiver, status) |
|
|
|
|
|
|
|
|
|
|
|
# The reblogging status should show up under normal conditions. |
|
|
|
# The reblogging status should show up under normal conditions. |
|
|
|
expect(Redis.current.zrange("feed:type:#{receiver.id}", 0, -1)).to eq [status.id.to_s] |
|
|
|
expect(Redis.current.zrange("feed:home:#{receiver.id}", 0, -1)).to eq [status.id.to_s] |
|
|
|
|
|
|
|
|
|
|
|
FeedManager.instance.unpush('type', receiver, status) |
|
|
|
FeedManager.instance.unpush_from_home(receiver, status) |
|
|
|
|
|
|
|
|
|
|
|
expect(Redis.current.zrange("feed:type:#{receiver.id}", 0, -1)).to be_empty |
|
|
|
expect(Redis.current.zrange("feed:home:#{receiver.id}", 0, -1)).to be_empty |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it 'leaves a multiply-reblogged status if another reblog was in feed' do |
|
|
|
it 'leaves a multiply-reblogged status if another reblog was in feed' do |
|
|
@ -377,26 +367,26 @@ RSpec.describe FeedManager do |
|
|
|
reblogs = 3.times.map { Fabricate(:status, reblog: reblogged) } |
|
|
|
reblogs = 3.times.map { Fabricate(:status, reblog: reblogged) } |
|
|
|
|
|
|
|
|
|
|
|
reblogs.each do |reblog| |
|
|
|
reblogs.each do |reblog| |
|
|
|
FeedManager.instance.push('type', receiver, reblog) |
|
|
|
FeedManager.instance.push_to_home(receiver, reblog) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
# The reblogging status should show up under normal conditions. |
|
|
|
# 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] |
|
|
|
expect(Redis.current.zrange("feed:home:#{receiver.id}", 0, -1)).to eq [reblogs.first.id.to_s] |
|
|
|
|
|
|
|
|
|
|
|
reblogs[0...-1].each do |reblog| |
|
|
|
reblogs[0...-1].each do |reblog| |
|
|
|
FeedManager.instance.unpush('type', receiver, reblog) |
|
|
|
FeedManager.instance.unpush_from_home(receiver, reblog) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
expect(Redis.current.zrange("feed:type:#{receiver.id}", 0, -1)).to eq [reblogs.last.id.to_s] |
|
|
|
expect(Redis.current.zrange("feed:home:#{receiver.id}", 0, -1)).to eq [reblogs.last.id.to_s] |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
it 'sends push updates' do |
|
|
|
it 'sends push updates' do |
|
|
|
status = Fabricate(:status) |
|
|
|
status = Fabricate(:status) |
|
|
|
|
|
|
|
|
|
|
|
FeedManager.instance.push('type', receiver, status) |
|
|
|
FeedManager.instance.push_to_home(receiver, status) |
|
|
|
|
|
|
|
|
|
|
|
allow(Redis.current).to receive_messages(publish: nil) |
|
|
|
allow(Redis.current).to receive_messages(publish: nil) |
|
|
|
FeedManager.instance.unpush('type', receiver, status) |
|
|
|
FeedManager.instance.unpush_from_home(receiver, status) |
|
|
|
|
|
|
|
|
|
|
|
deletion = Oj.dump(event: :delete, payload: status.id.to_s) |
|
|
|
deletion = Oj.dump(event: :delete, payload: status.id.to_s) |
|
|
|
expect(Redis.current).to have_received(:publish).with("timeline:#{receiver.id}", deletion) |
|
|
|
expect(Redis.current).to have_received(:publish).with("timeline:#{receiver.id}", deletion) |
|
|
|