public_feed_spec.rb 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. RSpec.describe PublicFeed do
  4. let(:account) { Fabricate(:account) }
  5. describe '#get' do
  6. subject { described_class.new(nil).get(20).map(&:id) }
  7. it 'only includes statuses with public visibility' do
  8. public_status = Fabricate(:status, visibility: :public)
  9. private_status = Fabricate(:status, visibility: :private)
  10. expect(subject).to include(public_status.id)
  11. expect(subject).to_not include(private_status.id)
  12. end
  13. it 'does not include replies' do
  14. status = Fabricate(:status)
  15. reply = Fabricate(:status, in_reply_to_id: status.id)
  16. expect(subject).to include(status.id)
  17. expect(subject).to_not include(reply.id)
  18. end
  19. it 'does not include boosts' do
  20. status = Fabricate(:status)
  21. boost = Fabricate(:status, reblog_of_id: status.id)
  22. expect(subject).to include(status.id)
  23. expect(subject).to_not include(boost.id)
  24. end
  25. it 'filters out silenced accounts' do
  26. silenced_account = Fabricate(:account, silenced: true)
  27. status = Fabricate(:status, account: account)
  28. silenced_status = Fabricate(:status, account: silenced_account)
  29. expect(subject).to include(status.id)
  30. expect(subject).to_not include(silenced_status.id)
  31. end
  32. context 'without local_only option' do
  33. subject { described_class.new(viewer).get(20).map(&:id) }
  34. let(:viewer) { nil }
  35. let!(:local_account) { Fabricate(:account, domain: nil) }
  36. let!(:remote_account) { Fabricate(:account, domain: 'test.com') }
  37. let!(:local_status) { Fabricate(:status, account: local_account) }
  38. let!(:remote_status) { Fabricate(:status, account: remote_account) }
  39. context 'without a viewer' do
  40. let(:viewer) { nil }
  41. it 'includes remote instances statuses and local statuses' do
  42. expect(subject)
  43. .to include(remote_status.id)
  44. .and include(local_status.id)
  45. end
  46. end
  47. context 'with a viewer' do
  48. let(:viewer) { Fabricate(:account, username: 'viewer') }
  49. it 'includes remote instances statuses and local statuses' do
  50. expect(subject)
  51. .to include(remote_status.id)
  52. .and include(local_status.id)
  53. end
  54. end
  55. end
  56. context 'with a local_only option set' do
  57. subject { described_class.new(viewer, local: true).get(20).map(&:id) }
  58. let!(:local_account) { Fabricate(:account, domain: nil) }
  59. let!(:remote_account) { Fabricate(:account, domain: 'test.com') }
  60. let!(:local_status) { Fabricate(:status, account: local_account) }
  61. let!(:remote_status) { Fabricate(:status, account: remote_account) }
  62. context 'without a viewer' do
  63. let(:viewer) { nil }
  64. it 'does not include remote instances statuses' do
  65. expect(subject).to include(local_status.id)
  66. expect(subject).to_not include(remote_status.id)
  67. end
  68. end
  69. context 'with a viewer' do
  70. let(:viewer) { Fabricate(:account, username: 'viewer') }
  71. it 'does not include remote instances statuses' do
  72. expect(subject).to include(local_status.id)
  73. expect(subject).to_not include(remote_status.id)
  74. end
  75. it 'is not affected by personal domain blocks' do
  76. viewer.block_domain!('test.com')
  77. expect(subject).to include(local_status.id)
  78. expect(subject).to_not include(remote_status.id)
  79. end
  80. end
  81. end
  82. context 'with a remote_only option set' do
  83. subject { described_class.new(viewer, remote: true).get(20).map(&:id) }
  84. let!(:local_account) { Fabricate(:account, domain: nil) }
  85. let!(:remote_account) { Fabricate(:account, domain: 'test.com') }
  86. let!(:local_status) { Fabricate(:status, account: local_account) }
  87. let!(:remote_status) { Fabricate(:status, account: remote_account) }
  88. context 'without a viewer' do
  89. let(:viewer) { nil }
  90. it 'does not include local instances statuses' do
  91. expect(subject).to_not include(local_status.id)
  92. expect(subject).to include(remote_status.id)
  93. end
  94. end
  95. context 'with a viewer' do
  96. let(:viewer) { Fabricate(:account, username: 'viewer') }
  97. it 'does not include local instances statuses' do
  98. expect(subject).to_not include(local_status.id)
  99. expect(subject).to include(remote_status.id)
  100. end
  101. end
  102. end
  103. describe 'with an account passed in' do
  104. subject { described_class.new(account).get(20).map(&:id) }
  105. let!(:account) { Fabricate(:account) }
  106. it 'excludes statuses from accounts blocked by the account' do
  107. blocked = Fabricate(:account)
  108. account.block!(blocked)
  109. blocked_status = Fabricate(:status, account: blocked)
  110. expect(subject).to_not include(blocked_status.id)
  111. end
  112. it 'excludes statuses from accounts who have blocked the account' do
  113. blocker = Fabricate(:account)
  114. blocker.block!(account)
  115. blocked_status = Fabricate(:status, account: blocker)
  116. expect(subject).to_not include(blocked_status.id)
  117. end
  118. it 'excludes statuses from accounts muted by the account' do
  119. muted = Fabricate(:account)
  120. account.mute!(muted)
  121. muted_status = Fabricate(:status, account: muted)
  122. expect(subject).to_not include(muted_status.id)
  123. end
  124. it 'excludes statuses from accounts from personally blocked domains' do
  125. blocked = Fabricate(:account, domain: 'example.com')
  126. account.block_domain!(blocked.domain)
  127. blocked_status = Fabricate(:status, account: blocked)
  128. expect(subject).to_not include(blocked_status.id)
  129. end
  130. context 'with language preferences' do
  131. it 'excludes statuses in languages not allowed by the account user' do
  132. account.user.update(chosen_languages: [:en, :es])
  133. en_status = Fabricate(:status, language: 'en')
  134. es_status = Fabricate(:status, language: 'es')
  135. fr_status = Fabricate(:status, language: 'fr')
  136. expect(subject).to include(en_status.id)
  137. expect(subject).to include(es_status.id)
  138. expect(subject).to_not include(fr_status.id)
  139. end
  140. it 'includes all languages when user does not have a setting' do
  141. account.user.update(chosen_languages: nil)
  142. en_status = Fabricate(:status, language: 'en')
  143. es_status = Fabricate(:status, language: 'es')
  144. expect(subject).to include(en_status.id)
  145. expect(subject).to include(es_status.id)
  146. end
  147. it 'includes all languages when account does not have a user' do
  148. account.update(user: nil)
  149. en_status = Fabricate(:status, language: 'en')
  150. es_status = Fabricate(:status, language: 'es')
  151. expect(subject).to include(en_status.id)
  152. expect(subject).to include(es_status.id)
  153. end
  154. end
  155. end
  156. end
  157. end