deletes_controller_spec.rb 2.6 KB

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