following_accounts_controller_spec.rb 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. require 'rails_helper'
  2. describe FollowingAccountsController do
  3. render_views
  4. let(:alice) { Fabricate(:account, username: 'alice') }
  5. let(:followee0) { Fabricate(:account) }
  6. let(:followee1) { Fabricate(:account) }
  7. describe 'GET #index' do
  8. let!(:follow0) { alice.follow!(followee0) }
  9. let!(:follow1) { alice.follow!(followee1) }
  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!(followee0)
  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