public_feed_spec.rb 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. require 'rails_helper'
  2. RSpec.describe PublicFeed, type: :model do
  3. let(:account) { Fabricate(:account) }
  4. describe '#get' do
  5. subject { described_class.new(nil).get(20).map(&:id) }
  6. it 'only includes statuses with public visibility' do
  7. public_status = Fabricate(:status, visibility: :public)
  8. private_status = Fabricate(:status, visibility: :private)
  9. expect(subject).to include(public_status.id)
  10. expect(subject).not_to include(private_status.id)
  11. end
  12. it 'does not include replies' do
  13. status = Fabricate(:status)
  14. reply = Fabricate(:status, in_reply_to_id: status.id)
  15. expect(subject).to include(status.id)
  16. expect(subject).not_to include(reply.id)
  17. end
  18. it 'does not include boosts' do
  19. status = Fabricate(:status)
  20. boost = Fabricate(:status, reblog_of_id: status.id)
  21. expect(subject).to include(status.id)
  22. expect(subject).not_to include(boost.id)
  23. end
  24. it 'filters out silenced accounts' do
  25. account = Fabricate(:account)
  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).not_to include(silenced_status.id)
  31. end
  32. context 'without local_only option' do
  33. let(:viewer) { nil }
  34. let!(:local_account) { Fabricate(:account, domain: nil) }
  35. let!(:remote_account) { Fabricate(:account, domain: 'test.com') }
  36. let!(:local_status) { Fabricate(:status, account: local_account) }
  37. let!(:remote_status) { Fabricate(:status, account: remote_account) }
  38. subject { described_class.new(viewer).get(20).map(&:id) }
  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. let!(:local_account) { Fabricate(:account, domain: nil) }
  60. let!(:remote_account) { Fabricate(:account, domain: 'test.com') }
  61. let!(:local_status) { Fabricate(:status, account: local_account) }
  62. let!(:remote_status) { Fabricate(:status, account: remote_account) }
  63. subject { described_class.new(viewer, local: true).get(20).map(&:id) }
  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).not_to 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).not_to 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).not_to include(remote_status.id)
  81. end
  82. end
  83. end
  84. context 'with a remote_only option set' do
  85. let!(:local_account) { Fabricate(:account, domain: nil) }
  86. let!(:remote_account) { Fabricate(:account, domain: 'test.com') }
  87. let!(:local_status) { Fabricate(:status, account: local_account) }
  88. let!(:remote_status) { Fabricate(:status, account: remote_account) }
  89. subject { described_class.new(viewer, remote: true).get(20).map(&:id) }
  90. context 'without a viewer' do
  91. let(:viewer) { nil }
  92. it 'does not include local instances statuses' do
  93. expect(subject).not_to 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).not_to 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. before do
  107. @account = Fabricate(:account)
  108. end
  109. subject { described_class.new(@account).get(20).map(&:id) }
  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).not_to 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).not_to 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).not_to 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).not_to 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. user = Fabricate(:user, chosen_languages: [:en, :es])
  137. @account.update(user: user)
  138. en_status = Fabricate(:status, language: 'en')
  139. es_status = Fabricate(:status, language: 'es')
  140. fr_status = Fabricate(:status, language: 'fr')
  141. expect(subject).to include(en_status.id)
  142. expect(subject).to include(es_status.id)
  143. expect(subject).not_to include(fr_status.id)
  144. end
  145. it 'includes all languages when user does not have a setting' do
  146. user = Fabricate(:user, chosen_languages: nil)
  147. @account.update(user: user)
  148. en_status = Fabricate(:status, language: 'en')
  149. es_status = Fabricate(:status, language: 'es')
  150. expect(subject).to include(en_status.id)
  151. expect(subject).to include(es_status.id)
  152. end
  153. it 'includes all languages when account does not have a user' do
  154. expect(@account.user).to be_nil
  155. en_status = Fabricate(:status, language: 'en')
  156. es_status = Fabricate(:status, language: 'es')
  157. expect(subject).to include(en_status.id)
  158. expect(subject).to include(es_status.id)
  159. end
  160. end
  161. end
  162. end
  163. end