challenges_controller_spec.rb 1.1 KB

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