Sha256: c50aeeb74d4fbd4565638b5cd8123e7504ade1e528dacbc84546b516073457b7

Contents?: true

Size: 1.1 KB

Versions: 2

Compression:

Stored size: 1.1 KB

Contents

class ActionDispatch::IntegrationTest

  def warden
    request.env['warden']
  end
  
  def create_full_user
    @user ||= begin
      user = User.create!(
        :email                 => 'user@email.invalid',
        :password              => '12345678',
        :password_confirmation => '12345678'
      )
      user
    end
  end

  def enable_otp_and_sign_in_with_otp
    enable_otp_and_sign_in.tap do |user|
      fill_in 'user_token', :with => ROTP::TOTP.new(user.otp_auth_secret).at(Time.now)
      click_button 'Submit Token'
    end
  end


  def enable_otp_and_sign_in
    user = create_full_user
    sign_user_in(user)
    visit user_otp_token_path
    check 'user_otp_enabled'
    click_button 'Continue...'

    Capybara.reset_sessions!

    sign_user_in(user)
    user
  end

  def sign_user_in(user = nil)
    user ||= create_full_user
    resource_name = user.class.name.underscore
    visit send("new_#{resource_name}_session_path")
    fill_in "#{resource_name}_email", :with => user.email
    fill_in "#{resource_name}_password", :with => user.password
    click_button 'Sign in'
    user
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
devise-otp-0.2.0 test/integration_tests_helper.rb
devise-otp-0.1.1 test/integration_tests_helper.rb