2023-02-22 02:55:31 +02:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-03-19 13:13:47 +02:00
|
|
|
require 'rails_helper'
|
|
|
|
|
2018-05-02 19:58:48 +03:00
|
|
|
RSpec.describe FanOutOnWriteService, type: :service do
|
2023-02-20 06:24:14 +02:00
|
|
|
subject { described_class.new }
|
|
|
|
|
2022-01-19 23:37:27 +02:00
|
|
|
let(:last_active_at) { Time.now.utc }
|
2023-02-20 04:17:41 +02:00
|
|
|
let(:status) { Fabricate(:status, account: alice, visibility: visibility, text: 'Hello @bob #hoge') }
|
2016-11-06 16:56:34 +02:00
|
|
|
|
2022-01-28 01:46:42 +02:00
|
|
|
let!(:alice) { Fabricate(:user, current_sign_in_at: last_active_at).account }
|
|
|
|
let!(:bob) { Fabricate(:user, current_sign_in_at: last_active_at, account_attributes: { username: 'bob' }).account }
|
|
|
|
let!(:tom) { Fabricate(:user, current_sign_in_at: last_active_at).account }
|
2022-01-19 23:37:27 +02:00
|
|
|
|
2016-11-06 16:56:34 +02:00
|
|
|
before do
|
2022-01-19 23:37:27 +02:00
|
|
|
bob.follow!(alice)
|
|
|
|
tom.follow!(alice)
|
2016-11-06 16:56:34 +02:00
|
|
|
|
|
|
|
ProcessMentionsService.new.call(status)
|
|
|
|
ProcessHashtagsService.new.call(status)
|
|
|
|
|
2022-04-28 18:47:34 +03:00
|
|
|
allow(redis).to receive(:publish)
|
2022-01-19 23:37:27 +02:00
|
|
|
|
2016-11-06 16:56:34 +02:00
|
|
|
subject.call(status)
|
|
|
|
end
|
|
|
|
|
2022-01-19 23:37:27 +02:00
|
|
|
def home_feed_of(account)
|
|
|
|
HomeFeed.new(account).get(10).map(&:id)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when status is public' do
|
|
|
|
let(:visibility) { 'public' }
|
|
|
|
|
|
|
|
it 'is added to the home feed of its author' do
|
|
|
|
expect(home_feed_of(alice)).to include status.id
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is added to the home feed of a follower' do
|
|
|
|
expect(home_feed_of(bob)).to include status.id
|
|
|
|
expect(home_feed_of(tom)).to include status.id
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is broadcast to the hashtag stream' do
|
2022-04-28 18:47:34 +03:00
|
|
|
expect(redis).to have_received(:publish).with('timeline:hashtag:hoge', anything)
|
|
|
|
expect(redis).to have_received(:publish).with('timeline:hashtag:hoge:local', anything)
|
2022-01-19 23:37:27 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'is broadcast to the public stream' do
|
2022-04-28 18:47:34 +03:00
|
|
|
expect(redis).to have_received(:publish).with('timeline:public', anything)
|
|
|
|
expect(redis).to have_received(:publish).with('timeline:public:local', anything)
|
2022-01-19 23:37:27 +02:00
|
|
|
end
|
2016-11-06 16:56:34 +02:00
|
|
|
end
|
|
|
|
|
2022-01-19 23:37:27 +02:00
|
|
|
context 'when status is limited' do
|
|
|
|
let(:visibility) { 'limited' }
|
|
|
|
|
|
|
|
it 'is added to the home feed of its author' do
|
|
|
|
expect(home_feed_of(alice)).to include status.id
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is added to the home feed of the mentioned follower' do
|
|
|
|
expect(home_feed_of(bob)).to include status.id
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is not added to the home feed of the other follower' do
|
|
|
|
expect(home_feed_of(tom)).to_not include status.id
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is not broadcast publicly' do
|
2022-04-28 18:47:34 +03:00
|
|
|
expect(redis).to_not have_received(:publish).with('timeline:hashtag:hoge', anything)
|
|
|
|
expect(redis).to_not have_received(:publish).with('timeline:public', anything)
|
2022-01-19 23:37:27 +02:00
|
|
|
end
|
2016-11-06 16:56:34 +02:00
|
|
|
end
|
|
|
|
|
2022-01-19 23:37:27 +02:00
|
|
|
context 'when status is private' do
|
|
|
|
let(:visibility) { 'private' }
|
|
|
|
|
|
|
|
it 'is added to the home feed of its author' do
|
|
|
|
expect(home_feed_of(alice)).to include status.id
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is added to the home feed of a follower' do
|
|
|
|
expect(home_feed_of(bob)).to include status.id
|
|
|
|
expect(home_feed_of(tom)).to include status.id
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is not broadcast publicly' do
|
2022-04-28 18:47:34 +03:00
|
|
|
expect(redis).to_not have_received(:publish).with('timeline:hashtag:hoge', anything)
|
|
|
|
expect(redis).to_not have_received(:publish).with('timeline:public', anything)
|
2022-01-19 23:37:27 +02:00
|
|
|
end
|
2016-11-06 16:56:34 +02:00
|
|
|
end
|
|
|
|
|
2022-01-19 23:37:27 +02:00
|
|
|
context 'when status is direct' do
|
|
|
|
let(:visibility) { 'direct' }
|
|
|
|
|
|
|
|
it 'is added to the home feed of its author' do
|
|
|
|
expect(home_feed_of(alice)).to include status.id
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is added to the home feed of the mentioned follower' do
|
|
|
|
expect(home_feed_of(bob)).to include status.id
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is not added to the home feed of the other follower' do
|
|
|
|
expect(home_feed_of(tom)).to_not include status.id
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'is not broadcast publicly' do
|
2022-04-28 18:47:34 +03:00
|
|
|
expect(redis).to_not have_received(:publish).with('timeline:hashtag:hoge', anything)
|
|
|
|
expect(redis).to_not have_received(:publish).with('timeline:public', anything)
|
2022-01-19 23:37:27 +02:00
|
|
|
end
|
2016-11-06 16:56:34 +02:00
|
|
|
end
|
2016-03-19 13:13:47 +02:00
|
|
|
end
|