public_feed_spec.rb 6.9 KB

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