authenticated.rb 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
  2. # This file registers a hook before each system test
  3. # which logs in with/authenticates the admin@example.com account.
  4. # we need to make sure that Capybara is configured/started before
  5. # this hook. Otherwise a login try is performed while the app/puma
  6. # hasn't started yet.
  7. require_relative './driven_by'
  8. RSpec.configure do |config|
  9. config.before(:each, type: :system) do |example|
  10. ENV['FAKE_SELENIUM_LOGIN_USER_ID'] = nil
  11. # there is no way to authenticated in a not set up system
  12. next if !example.metadata.fetch(:set_up, true)
  13. authenticated = example.metadata.fetch(:authenticated_as, true)
  14. credentials = authenticated_as_get_user(authenticated, return_type: :credentials)
  15. authentication_type = example.metadata.fetch(:authentication_type, :auto)
  16. next if credentials.nil?
  17. if authentication_type == :form
  18. login(**credentials)
  19. else
  20. ENV['FAKE_SELENIUM_LOGIN_USER_ID'] = User.find_by(email: credentials[:username]).id.to_s
  21. visit '/'
  22. wait.until_exists do
  23. current_login
  24. end
  25. end
  26. end
  27. end