public_feed_spec.rb 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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' do
  42. expect(subject).to include(remote_status.id)
  43. end
  44. it 'includes local statuses' do
  45. expect(subject).to include(local_status.id)
  46. end
  47. end
  48. context 'with a viewer' do
  49. let(:viewer) { Fabricate(:account, username: 'viewer') }
  50. it 'includes remote instances statuses' do
  51. expect(subject).to include(remote_status.id)
  52. end
  53. it 'includes local statuses' do
  54. expect(subject).to include(local_status.id)
  55. end
  56. end
  57. end
  58. context 'with a local_only option set' do
  59. subject { described_class.new(viewer, local: true).get(20).map(&:id) }
  60. let!(:local_account) { Fabricate(:account, domain: nil) }
  61. let!(:remote_account) { Fabricate(:account, domain: 'test.com') }
  62. let!(:local_status) { Fabricate(:status, account: local_account) }
  63. let!(:remote_status) { Fabricate(:status, account: remote_account) }
  64. context 'without a viewer' do
  65. let(:viewer) { nil }
  66. it 'does not include remote instances statuses' do
  67. expect(subject).to include(local_status.id)
  68. expect(subject).to_not include(remote_status.id)
  69. end
  70. end
  71. context 'with a viewer' do
  72. let(:viewer) { Fabricate(:account, username: 'viewer') }
  73. it 'does not include remote instances statuses' do
  74. expect(subject).to include(local_status.id)
  75. expect(subject).to_not include(remote_status.id)
  76. end
  77. it 'is not affected by personal domain blocks' do
  78. viewer.block_domain!('test.com')
  79. expect(subject).to include(local_status.id)
  80. expect(subject).to_not include(remote_status.id)
  81. end
  82. end
  83. end
  84. context 'with a remote_only option set' do
  85. subject { described_class.new(viewer, remote: true).get(20).map(&:id) }
  86. let!(:local_account) { Fabricate(:account, domain: nil) }
  87. let!(:remote_account) { Fabricate(:account, domain: 'test.com') }
  88. let!(:local_status) { Fabricate(:status, account: local_account) }
  89. let!(:remote_status) { Fabricate(:status, account: remote_account) }
  90. context 'without a viewer' do
  91. let(:viewer) { nil }
  92. it 'does not include local instances statuses' do
  93. expect(subject).to_not include(local_status.id)
  94. expect(subject).to include(remote_status.id)
  95. end
  96. end
  97. context 'with a viewer' do
  98. let(:viewer) { Fabricate(:account, username: 'viewer') }
  99. it 'does not include local instances statuses' do
  100. expect(subject).to_not include(local_status.id)
  101. expect(subject).to include(remote_status.id)
  102. end
  103. end
  104. end
  105. describe 'with an account passed in' do
  106. subject { described_class.new(@account).get(20).map(&:id) }
  107. before do
  108. @account = Fabricate(:account)
  109. end
  110. it 'excludes statuses from accounts blocked by the account' do
  111. blocked = Fabricate(:account)
  112. @account.block!(blocked)
  113. blocked_status = Fabricate(:status, account: blocked)
  114. expect(subject).to_not include(blocked_status.id)
  115. end
  116. it 'excludes statuses from accounts who have blocked the account' do
  117. blocker = Fabricate(:account)
  118. blocker.block!(@account)
  119. blocked_status = Fabricate(:status, account: blocker)
  120. expect(subject).to_not include(blocked_status.id)
  121. end
  122. it 'excludes statuses from accounts muted by the account' do
  123. muted = Fabricate(:account)
  124. @account.mute!(muted)
  125. muted_status = Fabricate(:status, account: muted)
  126. expect(subject).to_not include(muted_status.id)
  127. end
  128. it 'excludes statuses from accounts from personally blocked domains' do
  129. blocked = Fabricate(:account, domain: 'example.com')
  130. @account.block_domain!(blocked.domain)
  131. blocked_status = Fabricate(:status, account: blocked)
  132. expect(subject).to_not include(blocked_status.id)
  133. end
  134. context 'with language preferences' do
  135. it 'excludes statuses in languages not allowed by the account user' do
  136. @account.user.update(chosen_languages: [:en, :es])
  137. en_status = Fabricate(:status, language: 'en')
  138. es_status = Fabricate(:status, language: 'es')
  139. fr_status = Fabricate(:status, language: 'fr')
  140. expect(subject).to include(en_status.id)
  141. expect(subject).to include(es_status.id)
  142. expect(subject).to_not include(fr_status.id)
  143. end
  144. it 'includes all languages when user does not have a setting' do
  145. @account.user.update(chosen_languages: nil)
  146. en_status = Fabricate(:status, language: 'en')
  147. es_status = Fabricate(:status, language: 'es')
  148. expect(subject).to include(en_status.id)
  149. expect(subject).to include(es_status.id)
  150. end
  151. it 'includes all languages when account does not have a user' do
  152. @account.update(user: nil)
  153. en_status = Fabricate(:status, language: 'en')
  154. es_status = Fabricate(:status, language: 'es')
  155. expect(subject).to include(en_status.id)
  156. expect(subject).to include(es_status.id)
  157. end
  158. end
  159. end
  160. end
  161. end