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.

127 lines
3.3 KiB

  1. require 'rails_helper'
  2. describe FollowerAccountsController do
  3. render_views
  4. let(:alice) { Fabricate(:account, username: 'alice') }
  5. let(:follower0) { Fabricate(:account) }
  6. let(:follower1) { Fabricate(:account) }
  7. describe 'GET #index' do
  8. let!(:follow0) { follower0.follow!(alice) }
  9. let!(:follow1) { follower1.follow!(alice) }
  10. context 'when format is html' do
  11. subject(:response) { get :index, params: { account_username: alice.username, format: :html } }
  12. context 'when account is permanently suspended' do
  13. before do
  14. alice.suspend!
  15. alice.deletion_request.destroy
  16. end
  17. it 'returns http gone' do
  18. expect(response).to have_http_status(410)
  19. end
  20. end
  21. context 'when account is temporarily suspended' do
  22. before do
  23. alice.suspend!
  24. end
  25. it 'returns http forbidden' do
  26. expect(response).to have_http_status(403)
  27. end
  28. end
  29. it 'assigns follows' do
  30. expect(response).to have_http_status(200)
  31. assigned = assigns(:follows).to_a
  32. expect(assigned.size).to eq 2
  33. expect(assigned[0]).to eq follow1
  34. expect(assigned[1]).to eq follow0
  35. end
  36. it 'does not assign blocked users' do
  37. user = Fabricate(:user)
  38. user.account.block!(follower0)
  39. sign_in(user)
  40. expect(response).to have_http_status(200)
  41. assigned = assigns(:follows).to_a
  42. expect(assigned.size).to eq 1
  43. expect(assigned[0]).to eq follow1
  44. end
  45. end
  46. context 'when format is json' do
  47. subject(:response) { get :index, params: { account_username: alice.username, page: page, format: :json } }
  48. subject(:body) { JSON.parse(response.body) }
  49. context 'with page' do
  50. let(:page) { 1 }
  51. it 'returns followers' do
  52. expect(response).to have_http_status(200)
  53. expect(body['totalItems']).to eq 2
  54. expect(body['partOf']).to be_present
  55. end
  56. context 'when account is permanently suspended' do
  57. before do
  58. alice.suspend!
  59. alice.deletion_request.destroy
  60. end
  61. it 'returns http gone' do
  62. expect(response).to have_http_status(410)
  63. end
  64. end
  65. context 'when account is temporarily suspended' do
  66. before do
  67. alice.suspend!
  68. end
  69. it 'returns http forbidden' do
  70. expect(response).to have_http_status(403)
  71. end
  72. end
  73. end
  74. context 'without page' do
  75. let(:page) { nil }
  76. it 'returns followers' do
  77. expect(response).to have_http_status(200)
  78. expect(body['totalItems']).to eq 2
  79. expect(body['partOf']).to be_blank
  80. end
  81. context 'when account is permanently suspended' do
  82. before do
  83. alice.suspend!
  84. alice.deletion_request.destroy
  85. end
  86. it 'returns http gone' do
  87. expect(response).to have_http_status(410)
  88. end
  89. end
  90. context 'when account is temporarily suspended' do
  91. before do
  92. alice.suspend!
  93. end
  94. it 'returns http forbidden' do
  95. expect(response).to have_http_status(403)
  96. end
  97. end
  98. end
  99. end
  100. end
  101. end