challenges_controller_spec.rb 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe Auth::ChallengesController, type: :controller do
  4. render_views
  5. let(:password) { 'foobar12345' }
  6. let(:user) { Fabricate(:user, password: password) }
  7. before do
  8. sign_in user
  9. end
  10. describe 'POST #create' do
  11. let(:return_to) { edit_user_registration_path }
  12. context 'with correct password' do
  13. before { post :create, params: { form_challenge: { return_to: return_to, current_password: password } } }
  14. it 'redirects back' do
  15. expect(response).to redirect_to(return_to)
  16. end
  17. it 'sets session' do
  18. expect(session[:challenge_passed_at]).to_not be_nil
  19. end
  20. end
  21. context 'with incorrect password' do
  22. before { post :create, params: { form_challenge: { return_to: return_to, current_password: 'hhfggjjd562' } } }
  23. it 'renders challenge' do
  24. expect(response).to render_template('auth/challenges/new')
  25. end
  26. it 'displays error' do
  27. expect(response.body).to include 'Invalid password'
  28. end
  29. it 'does not set session' do
  30. expect(session[:challenge_passed_at]).to be_nil
  31. end
  32. end
  33. end
  34. end