闭社主体 forked from https://github.com/tootsuite/mastodon
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.

126 lines
5.1 KiB

  1. require 'rails_helper'
  2. RSpec.describe FeedManager do
  3. describe '#key' do
  4. subject { FeedManager.instance.key(:home, 1) }
  5. it 'returns a string' do
  6. expect(subject).to be_a String
  7. end
  8. end
  9. describe '#filter?' do
  10. let(:alice) { Fabricate(:account, username: 'alice') }
  11. let(:bob) { Fabricate(:account, username: 'bob') }
  12. let(:jeff) { Fabricate(:account, username: 'jeff') }
  13. context 'for home feed' do
  14. it 'returns false for followee\'s status' do
  15. status = Fabricate(:status, text: 'Hello world', account: alice)
  16. bob.follow!(alice)
  17. expect(FeedManager.instance.filter?(:home, status, bob.id)).to be false
  18. end
  19. it 'returns false for reblog by followee' do
  20. status = Fabricate(:status, text: 'Hello world', account: jeff)
  21. reblog = Fabricate(:status, reblog: status, account: alice)
  22. bob.follow!(alice)
  23. expect(FeedManager.instance.filter?(:home, reblog, bob.id)).to be false
  24. end
  25. it 'returns true for reblog by followee of blocked account' do
  26. status = Fabricate(:status, text: 'Hello world', account: jeff)
  27. reblog = Fabricate(:status, reblog: status, account: alice)
  28. bob.follow!(alice)
  29. bob.block!(jeff)
  30. expect(FeedManager.instance.filter?(:home, reblog, bob.id)).to be true
  31. end
  32. it 'returns true for reblog by followee of muted account' do
  33. status = Fabricate(:status, text: 'Hello world', account: jeff)
  34. reblog = Fabricate(:status, reblog: status, account: alice)
  35. bob.follow!(alice)
  36. bob.mute!(jeff)
  37. expect(FeedManager.instance.filter?(:home, reblog, bob.id)).to be true
  38. end
  39. it 'returns true for reblog by followee of someone who is blocking recipient' do
  40. status = Fabricate(:status, text: 'Hello world', account: jeff)
  41. reblog = Fabricate(:status, reblog: status, account: alice)
  42. bob.follow!(alice)
  43. jeff.block!(bob)
  44. expect(FeedManager.instance.filter?(:home, reblog, bob.id)).to be true
  45. end
  46. it 'returns false for reply by followee to another followee' do
  47. status = Fabricate(:status, text: 'Hello world', account: jeff)
  48. reply = Fabricate(:status, text: 'Nay', thread: status, account: alice)
  49. bob.follow!(alice)
  50. bob.follow!(jeff)
  51. expect(FeedManager.instance.filter?(:home, reply, bob.id)).to be false
  52. end
  53. it 'returns false for reply by followee to recipient' do
  54. status = Fabricate(:status, text: 'Hello world', account: bob)
  55. reply = Fabricate(:status, text: 'Nay', thread: status, account: alice)
  56. bob.follow!(alice)
  57. expect(FeedManager.instance.filter?(:home, reply, bob.id)).to be false
  58. end
  59. it 'returns false for reply by followee to self' do
  60. status = Fabricate(:status, text: 'Hello world', account: alice)
  61. reply = Fabricate(:status, text: 'Nay', thread: status, account: alice)
  62. bob.follow!(alice)
  63. expect(FeedManager.instance.filter?(:home, reply, bob.id)).to be false
  64. end
  65. it 'returns true for reply by followee to non-followed account' do
  66. status = Fabricate(:status, text: 'Hello world', account: jeff)
  67. reply = Fabricate(:status, text: 'Nay', thread: status, account: alice)
  68. bob.follow!(alice)
  69. expect(FeedManager.instance.filter?(:home, reply, bob.id)).to be true
  70. end
  71. it 'returns false for status by followee mentioning another account' do
  72. bob.follow!(alice)
  73. status = PostStatusService.new.call(alice, 'Hey @jeff')
  74. expect(FeedManager.instance.filter?(:home, status, bob.id)).to be false
  75. end
  76. it 'returns true for status by followee mentioning blocked account' do
  77. bob.block!(jeff)
  78. bob.follow!(alice)
  79. status = PostStatusService.new.call(alice, 'Hey @jeff')
  80. expect(FeedManager.instance.filter?(:home, status, bob.id)).to be true
  81. end
  82. end
  83. context 'for mentions feed' do
  84. it 'returns true for status that mentions blocked account' do
  85. bob.block!(jeff)
  86. status = PostStatusService.new.call(alice, 'Hey @jeff')
  87. expect(FeedManager.instance.filter?(:mentions, status, bob.id)).to be true
  88. end
  89. it 'returns true for status that replies to a blocked account' do
  90. status = Fabricate(:status, text: 'Hello world', account: jeff)
  91. reply = Fabricate(:status, text: 'Nay', thread: status, account: alice)
  92. bob.block!(jeff)
  93. expect(FeedManager.instance.filter?(:mentions, reply, bob.id)).to be true
  94. end
  95. it 'returns true for status by silenced account who recipient is not following' do
  96. status = Fabricate(:status, text: 'Hello world', account: alice)
  97. alice.update(silenced: true)
  98. expect(FeedManager.instance.filter?(:mentions, status, bob.id)).to be true
  99. end
  100. it 'returns false for status by followed silenced account' do
  101. status = Fabricate(:status, text: 'Hello world', account: alice)
  102. alice.update(silenced: true)
  103. bob.follow!(alice)
  104. expect(FeedManager.instance.filter?(:mentions, status, bob.id)).to be false
  105. end
  106. end
  107. end
  108. end