confirmations_controller_spec.rb 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe Auth::ConfirmationsController, type: :controller 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 updating email' do
  28. let!(:user) { Fabricate(:user, confirmation_token: 'foobar', unconfirmed_email: 'new-email@example.com') }
  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. it 'does not queue up bootstrapping of home timeline' do
  38. expect(BootstrapTimelineWorker).to_not have_received(:perform_async)
  39. end
  40. end
  41. end
  42. describe 'GET #finish_signup' do
  43. subject { get :finish_signup }
  44. let(:user) { Fabricate(:user) }
  45. before do
  46. sign_in user, scope: :user
  47. @request.env['devise.mapping'] = Devise.mappings[:user]
  48. end
  49. it 'renders finish_signup' do
  50. is_expected.to render_template :finish_signup
  51. expect(assigns(:user)).to have_attributes id: user.id
  52. end
  53. end
  54. describe 'PATCH #finish_signup' do
  55. subject { patch :finish_signup, params: { user: { email: email } } }
  56. let(:user) { Fabricate(:user) }
  57. before do
  58. sign_in user, scope: :user
  59. @request.env['devise.mapping'] = Devise.mappings[:user]
  60. end
  61. context 'when email is valid' do
  62. let(:email) { 'new_' + user.email }
  63. it 'redirects to root_path' do
  64. is_expected.to redirect_to root_path
  65. end
  66. end
  67. context 'when email is invalid' do
  68. let(:email) { '' }
  69. it 'renders finish_signup' do
  70. is_expected.to render_template :finish_signup
  71. end
  72. end
  73. end
  74. end