two_factor_authentication_methods_controller_spec.rb 1020 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe Settings::TwoFactorAuthenticationMethodsController do
  4. render_views
  5. let(:user) { Fabricate(:user) }
  6. describe 'GET #index' do
  7. context 'when signed in' do
  8. before do
  9. sign_in user, scope: :user
  10. end
  11. describe 'when user has enabled otp' do
  12. before do
  13. user.update(otp_required_for_login: true)
  14. end
  15. it 'returns http success' do
  16. get :index
  17. expect(response).to have_http_status(200)
  18. end
  19. end
  20. describe 'when user has not enabled otp' do
  21. before do
  22. user.update(otp_required_for_login: false)
  23. end
  24. it 'redirects to enable otp' do
  25. get :index
  26. expect(response).to redirect_to(settings_otp_authentication_path)
  27. end
  28. end
  29. end
  30. context 'when not signed in' do
  31. it 'redirects' do
  32. get :index
  33. expect(response).to redirect_to '/auth/sign_in'
  34. end
  35. end
  36. end
  37. end