confirmations_controller_spec.rb 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe Auth::ConfirmationsController do
  4. render_views
  5. describe 'GET #new' do
  6. it 'returns http success' do
  7. @request.env['devise.mapping'] = Devise.mappings[:user]
  8. get :new
  9. expect(response).to have_http_status(200)
  10. end
  11. end
  12. describe 'GET #show' do
  13. context 'when user is unconfirmed' do
  14. let!(:user) { Fabricate(:user, confirmation_token: 'foobar', confirmed_at: nil) }
  15. before do
  16. allow(BootstrapTimelineWorker).to receive(:perform_async)
  17. @request.env['devise.mapping'] = Devise.mappings[:user]
  18. get :show, params: { confirmation_token: 'foobar' }
  19. end
  20. it 'redirects to login' do
  21. expect(response).to redirect_to(new_user_session_path)
  22. end
  23. it 'queues up bootstrapping of home timeline' do
  24. expect(BootstrapTimelineWorker).to have_received(:perform_async).with(user.account_id)
  25. end
  26. end
  27. context 'when user is unconfirmed and unapproved' do
  28. let!(:user) { Fabricate(:user, confirmation_token: 'foobar', confirmed_at: nil, approved: false) }
  29. before do
  30. allow(BootstrapTimelineWorker).to receive(:perform_async)
  31. @request.env['devise.mapping'] = Devise.mappings[:user]
  32. get :show, params: { confirmation_token: 'foobar' }
  33. end
  34. it 'redirects to login' do
  35. expect(response).to redirect_to(new_user_session_path)
  36. end
  37. end
  38. context 'when user is already confirmed' do
  39. let!(:user) { Fabricate(:user) }
  40. before do
  41. allow(BootstrapTimelineWorker).to receive(:perform_async)
  42. @request.env['devise.mapping'] = Devise.mappings[:user]
  43. sign_in(user, scope: :user)
  44. get :show, params: { confirmation_token: 'foobar' }
  45. end
  46. it 'redirects to root path' do
  47. expect(response).to redirect_to(root_path)
  48. end
  49. end
  50. context 'when user is already confirmed but unapproved' do
  51. let!(:user) { Fabricate(:user, approved: false) }
  52. before do
  53. allow(BootstrapTimelineWorker).to receive(:perform_async)
  54. @request.env['devise.mapping'] = Devise.mappings[:user]
  55. user.approved = false
  56. user.save!
  57. sign_in(user, scope: :user)
  58. get :show, params: { confirmation_token: 'foobar' }
  59. end
  60. it 'redirects to settings' do
  61. expect(response).to redirect_to(edit_user_registration_path)
  62. end
  63. end
  64. context 'when user is updating email' do
  65. let!(:user) { Fabricate(:user, confirmation_token: 'foobar', unconfirmed_email: 'new-email@example.com') }
  66. before do
  67. allow(BootstrapTimelineWorker).to receive(:perform_async)
  68. @request.env['devise.mapping'] = Devise.mappings[:user]
  69. get :show, params: { confirmation_token: 'foobar' }
  70. end
  71. it 'redirects to login' do
  72. expect(response).to redirect_to(new_user_session_path)
  73. end
  74. it 'does not queue up bootstrapping of home timeline' do
  75. expect(BootstrapTimelineWorker).to_not have_received(:perform_async)
  76. end
  77. end
  78. end
  79. end