captcha_spec.rb 1.4 KB

1234567891011121314151617181920212223242526272829303132333435
  1. # frozen_string_literal: true
  2. require 'rails_helper'
  3. describe 'email confirmation flow when captcha is enabled' do
  4. let(:user) { Fabricate(:user, confirmed_at: nil, confirmation_token: 'foobar', created_by_application: client_app) }
  5. let(:client_app) { nil }
  6. before do
  7. # rubocop:disable RSpec/AnyInstance -- easiest way to deal with that that I know of
  8. allow_any_instance_of(Auth::ConfirmationsController).to receive(:captcha_enabled?).and_return(true)
  9. allow_any_instance_of(Auth::ConfirmationsController).to receive(:check_captcha!).and_return(true)
  10. allow_any_instance_of(Auth::ConfirmationsController).to receive(:render_captcha).and_return(nil)
  11. # rubocop:enable RSpec/AnyInstance
  12. end
  13. context 'when the user signed up through an app' do
  14. let(:client_app) { Fabricate(:application) }
  15. it 'logs in' do
  16. visit "/auth/confirmation?confirmation_token=#{user.confirmation_token}&redirect_to_app=true"
  17. # It presents the user with a captcha form
  18. expect(page).to have_title(I18n.t('auth.captcha_confirmation.title'))
  19. # It does not confirm the user just yet
  20. expect(user.reload.confirmed?).to be false
  21. # It redirects to app and confirms user
  22. click_on I18n.t('challenge.confirm')
  23. expect(user.reload.confirmed?).to be true
  24. expect(page).to have_current_path(/\A#{client_app.confirmation_redirect_uri}/, url: true)
  25. end
  26. end
  27. end