You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
3.6 KiB

  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.current).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.current).to have_received(:publish).with('timeline:hashtag:hoge', anything)
  31. expect(Redis.current).to have_received(:publish).with('timeline:hashtag:hoge:local', anything)
  32. end
  33. it 'is broadcast to the public stream' do
  34. expect(Redis.current).to have_received(:publish).with('timeline:public', anything)
  35. expect(Redis.current).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.current).to_not have_received(:publish).with('timeline:hashtag:hoge', anything)
  51. expect(Redis.current).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.current).to_not have_received(:publish).with('timeline:hashtag:hoge', anything)
  65. expect(Redis.current).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.current).to_not have_received(:publish).with('timeline:hashtag:hoge', anything)
  81. expect(Redis.current).to_not have_received(:publish).with('timeline:public', anything)
  82. end
  83. end
  84. end