logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

status_threading_concern_spec.rb (4462B)


  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe StatusThreadingConcern do
  4. describe '#ancestors' do
  5. let!(:alice) { Fabricate(:account, username: 'alice') }
  6. let!(:bob) { Fabricate(:account, username: 'bob', domain: 'example.com') }
  7. let!(:jeff) { Fabricate(:account, username: 'jeff') }
  8. let!(:status) { Fabricate(:status, account: alice) }
  9. let!(:reply1) { Fabricate(:status, thread: status, account: jeff) }
  10. let!(:reply2) { Fabricate(:status, thread: reply1, account: bob) }
  11. let!(:reply3) { Fabricate(:status, thread: reply2, account: alice) }
  12. let!(:viewer) { Fabricate(:account, username: 'viewer') }
  13. it 'returns conversation history' do
  14. expect(reply3.ancestors(4)).to include(status, reply1, reply2)
  15. end
  16. it 'does not return conversation history user is not allowed to see' do
  17. reply1.update(visibility: :private)
  18. status.update(visibility: :direct)
  19. expect(reply3.ancestors(4, viewer)).to_not include(reply1, status)
  20. end
  21. it 'does not return conversation history from blocked users' do
  22. viewer.block!(jeff)
  23. expect(reply3.ancestors(4, viewer)).to_not include(reply1)
  24. end
  25. it 'does not return conversation history from muted users' do
  26. viewer.mute!(jeff)
  27. expect(reply3.ancestors(4, viewer)).to_not include(reply1)
  28. end
  29. it 'does not return conversation history from silenced and not followed users' do
  30. jeff.update(silenced: true)
  31. expect(reply3.ancestors(4, viewer)).to_not include(reply1)
  32. end
  33. it 'does not return conversation history from blocked domains' do
  34. viewer.block_domain!('example.com')
  35. expect(reply3.ancestors(4, viewer)).to_not include(reply2)
  36. end
  37. it 'ignores deleted records' do
  38. first_status = Fabricate(:status, account: bob)
  39. second_status = Fabricate(:status, thread: first_status, account: alice)
  40. # Create cache and delete cached record
  41. second_status.ancestors(4)
  42. first_status.destroy
  43. expect(second_status.ancestors(4)).to eq([])
  44. end
  45. it 'can return more records than previously requested' do
  46. first_status = Fabricate(:status, account: bob)
  47. second_status = Fabricate(:status, thread: first_status, account: alice)
  48. third_status = Fabricate(:status, thread: second_status, account: alice)
  49. # Create cache
  50. second_status.ancestors(1)
  51. expect(third_status.ancestors(2)).to eq([first_status, second_status])
  52. end
  53. it 'can return fewer records than previously requested' do
  54. first_status = Fabricate(:status, account: bob)
  55. second_status = Fabricate(:status, thread: first_status, account: alice)
  56. third_status = Fabricate(:status, thread: second_status, account: alice)
  57. # Create cache
  58. second_status.ancestors(2)
  59. expect(third_status.ancestors(1)).to eq([second_status])
  60. end
  61. end
  62. describe '#descendants' do
  63. let!(:alice) { Fabricate(:account, username: 'alice') }
  64. let!(:bob) { Fabricate(:account, username: 'bob', domain: 'example.com') }
  65. let!(:jeff) { Fabricate(:account, username: 'jeff') }
  66. let!(:status) { Fabricate(:status, account: alice) }
  67. let!(:reply1) { Fabricate(:status, thread: status, account: alice) }
  68. let!(:reply2) { Fabricate(:status, thread: status, account: bob) }
  69. let!(:reply3) { Fabricate(:status, thread: reply1, account: jeff) }
  70. let!(:viewer) { Fabricate(:account, username: 'viewer') }
  71. it 'returns replies' do
  72. expect(status.descendants).to include(reply1, reply2, reply3)
  73. end
  74. it 'does not return replies user is not allowed to see' do
  75. reply1.update(visibility: :private)
  76. reply3.update(visibility: :direct)
  77. expect(status.descendants(viewer)).to_not include(reply1, reply3)
  78. end
  79. it 'does not return replies from blocked users' do
  80. viewer.block!(jeff)
  81. expect(status.descendants(viewer)).to_not include(reply3)
  82. end
  83. it 'does not return replies from muted users' do
  84. viewer.mute!(jeff)
  85. expect(status.descendants(viewer)).to_not include(reply3)
  86. end
  87. it 'does not return replies from silenced and not followed users' do
  88. jeff.update(silenced: true)
  89. expect(status.descendants(viewer)).to_not include(reply3)
  90. end
  91. it 'does not return replies from blocked domains' do
  92. viewer.block_domain!('example.com')
  93. expect(status.descendants(viewer)).to_not include(reply2)
  94. end
  95. end
  96. end