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.

107 lines
2.7 KiB

  1. require 'rails_helper'
  2. describe Settings::DeletesController do
  3. render_views
  4. describe 'GET #show' do
  5. context 'when signed in' do
  6. let(:user) { Fabricate(:user) }
  7. before do
  8. sign_in user, scope: :user
  9. end
  10. it 'renders confirmation page' do
  11. get :show
  12. expect(response).to have_http_status(200)
  13. end
  14. context 'when suspended' do
  15. let(:user) { Fabricate(:user, account_attributes: { username: 'alice', suspended_at: Time.now.utc }) }
  16. it 'returns http forbidden' do
  17. get :show
  18. expect(response).to have_http_status(403)
  19. end
  20. end
  21. end
  22. context 'when not signed in' do
  23. it 'redirects' do
  24. get :show
  25. expect(response).to redirect_to '/auth/sign_in'
  26. end
  27. end
  28. end
  29. describe 'DELETE #destroy' do
  30. context 'when signed in' do
  31. let(:user) { Fabricate(:user, password: 'petsmoldoggos') }
  32. before do
  33. sign_in user, scope: :user
  34. end
  35. context 'with correct password' do
  36. before do
  37. delete :destroy, params: { form_delete_confirmation: { password: 'petsmoldoggos' } }
  38. end
  39. it 'redirects to sign in page' do
  40. expect(response).to redirect_to '/auth/sign_in'
  41. end
  42. it 'removes user record' do
  43. expect(User.find_by(id: user.id)).to be_nil
  44. end
  45. it 'marks account as suspended' do
  46. expect(user.account.reload).to be_suspended
  47. end
  48. it 'does not create an email block' do
  49. expect(CanonicalEmailBlock.block?(user.email)).to be false
  50. end
  51. context 'when suspended' do
  52. let(:user) { Fabricate(:user, account_attributes: { username: 'alice', suspended_at: Time.now.utc }) }
  53. it 'returns http forbidden' do
  54. expect(response).to have_http_status(403)
  55. end
  56. end
  57. end
  58. context 'with incorrect password' do
  59. before do
  60. delete :destroy, params: { form_delete_confirmation: { password: 'blaze420' } }
  61. end
  62. it 'redirects back to confirmation page' do
  63. expect(response).to redirect_to settings_delete_path
  64. end
  65. end
  66. context 'when account deletions are disabled' do
  67. around do |example|
  68. open_deletion = Setting.open_deletion
  69. example.run
  70. Setting.open_deletion = open_deletion
  71. end
  72. it 'redirects' do
  73. Setting.open_deletion = false
  74. delete :destroy
  75. expect(response).to redirect_to root_path
  76. end
  77. end
  78. end
  79. context 'when not signed in' do
  80. it 'redirects' do
  81. delete :destroy
  82. expect(response).to redirect_to '/auth/sign_in'
  83. end
  84. end
  85. end
  86. end