fan_out_on_write_service_spec.rb 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. require 'rails_helper'
  2. RSpec.describe FanOutOnWriteService, type: :service do
  3. let(:last_active_at) { Time.now.utc }
  4. let!(:alice) { Fabricate(:user, current_sign_in_at: last_active_at).account }
  5. let!(:bob) { Fabricate(:user, current_sign_in_at: last_active_at, account_attributes: { username: 'bob' }).account }
  6. let!(:tom) { Fabricate(:user, current_sign_in_at: last_active_at).account }
  7. subject { described_class.new }
  8. let(:status) { Fabricate(:status, account: alice, visibility: visibility, text: 'Hello @bob #hoge') }
  9. before do
  10. bob.follow!(alice)
  11. tom.follow!(alice)
  12. ProcessMentionsService.new.call(status)
  13. ProcessHashtagsService.new.call(status)
  14. allow(redis).to receive(:publish)
  15. subject.call(status)
  16. end
  17. def home_feed_of(account)
  18. HomeFeed.new(account).get(10).map(&:id)
  19. end
  20. context 'when status is public' do
  21. let(:visibility) { 'public' }
  22. it 'is added to the home feed of its author' do
  23. expect(home_feed_of(alice)).to include status.id
  24. end
  25. it 'is added to the home feed of a follower' do
  26. expect(home_feed_of(bob)).to include status.id
  27. expect(home_feed_of(tom)).to include status.id
  28. end
  29. it 'is broadcast to the hashtag stream' do
  30. expect(redis).to have_received(:publish).with('timeline:hashtag:hoge', anything)
  31. expect(redis).to have_received(:publish).with('timeline:hashtag:hoge:local', anything)
  32. end
  33. it 'is broadcast to the public stream' do
  34. expect(redis).to have_received(:publish).with('timeline:public', anything)
  35. expect(redis).to have_received(:publish).with('timeline:public:local', anything)
  36. end
  37. end
  38. context 'when status is limited' do
  39. let(:visibility) { 'limited' }
  40. it 'is added to the home feed of its author' do
  41. expect(home_feed_of(alice)).to include status.id
  42. end
  43. it 'is added to the home feed of the mentioned follower' do
  44. expect(home_feed_of(bob)).to include status.id
  45. end
  46. it 'is not added to the home feed of the other follower' do
  47. expect(home_feed_of(tom)).to_not include status.id
  48. end
  49. it 'is not broadcast publicly' do
  50. expect(redis).to_not have_received(:publish).with('timeline:hashtag:hoge', anything)
  51. expect(redis).to_not have_received(:publish).with('timeline:public', anything)
  52. end
  53. end
  54. context 'when status is private' do
  55. let(:visibility) { 'private' }
  56. it 'is added to the home feed of its author' do
  57. expect(home_feed_of(alice)).to include status.id
  58. end
  59. it 'is added to the home feed of a follower' do
  60. expect(home_feed_of(bob)).to include status.id
  61. expect(home_feed_of(tom)).to include status.id
  62. end
  63. it 'is not broadcast publicly' do
  64. expect(redis).to_not have_received(:publish).with('timeline:hashtag:hoge', anything)
  65. expect(redis).to_not have_received(:publish).with('timeline:public', anything)
  66. end
  67. end
  68. context 'when status is direct' do
  69. let(:visibility) { 'direct' }
  70. it 'is added to the home feed of its author' do
  71. expect(home_feed_of(alice)).to include status.id
  72. end
  73. it 'is added to the home feed of the mentioned follower' do
  74. expect(home_feed_of(bob)).to include status.id
  75. end
  76. it 'is not added to the home feed of the other follower' do
  77. expect(home_feed_of(tom)).to_not include status.id
  78. end
  79. it 'is not broadcast publicly' do
  80. expect(redis).to_not have_received(:publish).with('timeline:hashtag:hoge', anything)
  81. expect(redis).to_not have_received(:publish).with('timeline:public', anything)
  82. end
  83. end
  84. end