logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

deletes_controller_spec.rb (2022B)


  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(:success)
  13. end
  14. end
  15. context 'when not signed in' do
  16. it 'redirects' do
  17. get :show
  18. expect(response).to redirect_to '/auth/sign_in'
  19. end
  20. end
  21. end
  22. describe 'DELETE #destroy' do
  23. context 'when signed in' do
  24. let(:user) { Fabricate(:user, password: 'petsmoldoggos') }
  25. before do
  26. sign_in user, scope: :user
  27. end
  28. context 'with correct password' do
  29. before do
  30. delete :destroy, params: { form_delete_confirmation: { password: 'petsmoldoggos' } }
  31. end
  32. it 'redirects to sign in page' do
  33. expect(response).to redirect_to '/auth/sign_in'
  34. end
  35. it 'removes user record' do
  36. expect(User.find_by(id: user.id)).to be_nil
  37. end
  38. it 'marks account as suspended' do
  39. expect(user.account.reload).to be_suspended
  40. end
  41. end
  42. context 'with incorrect password' do
  43. before do
  44. delete :destroy, params: { form_delete_confirmation: { password: 'blaze420' } }
  45. end
  46. it 'redirects back to confirmation page' do
  47. expect(response).to redirect_to settings_delete_path
  48. end
  49. end
  50. end
  51. context 'when not signed in' do
  52. it 'redirects' do
  53. delete :destroy
  54. expect(response).to redirect_to '/auth/sign_in'
  55. end
  56. end
  57. context do
  58. around do |example|
  59. open_deletion = Setting.open_deletion
  60. example.run
  61. Setting.open_deletion = open_deletion
  62. end
  63. it 'redirects' do
  64. Setting.open_deletion = false
  65. delete :destroy
  66. expect(response).to redirect_to root_path
  67. end
  68. end
  69. end
  70. end