status_threading_concern_spec.rb 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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).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(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(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(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(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(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
  42. first_status.destroy
  43. expect(second_status.ancestors).to eq([])
  44. end
  45. end
  46. describe '#descendants' do
  47. let!(:alice) { Fabricate(:account, username: 'alice') }
  48. let!(:bob) { Fabricate(:account, username: 'bob', domain: 'example.com') }
  49. let!(:jeff) { Fabricate(:account, username: 'jeff') }
  50. let!(:status) { Fabricate(:status, account: alice) }
  51. let!(:reply1) { Fabricate(:status, thread: status, account: alice) }
  52. let!(:reply2) { Fabricate(:status, thread: status, account: bob) }
  53. let!(:reply3) { Fabricate(:status, thread: reply1, account: jeff) }
  54. let!(:viewer) { Fabricate(:account, username: 'viewer') }
  55. it 'returns replies' do
  56. expect(status.descendants).to include(reply1, reply2, reply3)
  57. end
  58. it 'does not return replies user is not allowed to see' do
  59. reply1.update(visibility: :private)
  60. reply3.update(visibility: :direct)
  61. expect(status.descendants(viewer)).to_not include(reply1, reply3)
  62. end
  63. it 'does not return replies from blocked users' do
  64. viewer.block!(jeff)
  65. expect(status.descendants(viewer)).to_not include(reply3)
  66. end
  67. it 'does not return replies from muted users' do
  68. viewer.mute!(jeff)
  69. expect(status.descendants(viewer)).to_not include(reply3)
  70. end
  71. it 'does not return replies from silenced and not followed users' do
  72. jeff.update(silenced: true)
  73. expect(status.descendants(viewer)).to_not include(reply3)
  74. end
  75. it 'does not return replies from blocked domains' do
  76. viewer.block_domain!('example.com')
  77. expect(status.descendants(viewer)).to_not include(reply2)
  78. end
  79. end
  80. end