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.

103 lines
2.6 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. context 'when suspended' do
  49. let(:user) { Fabricate(:user, account_attributes: { username: 'alice', suspended_at: Time.now.utc }) }
  50. it 'returns http forbidden' do
  51. expect(response).to have_http_status(403)
  52. end
  53. end
  54. end
  55. context 'with incorrect password' do
  56. before do
  57. delete :destroy, params: { form_delete_confirmation: { password: 'blaze420' } }
  58. end
  59. it 'redirects back to confirmation page' do
  60. expect(response).to redirect_to settings_delete_path
  61. end
  62. end
  63. context 'when account deletions are disabled' do
  64. around do |example|
  65. open_deletion = Setting.open_deletion
  66. example.run
  67. Setting.open_deletion = open_deletion
  68. end
  69. it 'redirects' do
  70. Setting.open_deletion = false
  71. delete :destroy
  72. expect(response).to redirect_to root_path
  73. end
  74. end
  75. end
  76. context 'when not signed in' do
  77. it 'redirects' do
  78. delete :destroy
  79. expect(response).to redirect_to '/auth/sign_in'
  80. end
  81. end
  82. end
  83. end