2018-12-19 14:47:15 +00:00
|
|
|
# This file registers a hook before each system test
|
|
|
|
# which logs in with/authenticates the master@example.com account.
|
|
|
|
|
|
|
|
# we need to make sure that Capybara is configured/started before
|
|
|
|
# this hook. Otherwise a login try is performed while the app/puma
|
|
|
|
# hasn't started yet.
|
|
|
|
require_relative './driven_by'
|
|
|
|
|
|
|
|
RSpec.configure do |config|
|
|
|
|
|
|
|
|
config.before(:each, type: :system) do |example|
|
|
|
|
|
|
|
|
# there is no way to authenticated in a not set up system
|
|
|
|
next if !example.metadata.fetch(:set_up, true)
|
|
|
|
|
|
|
|
# check if authentication should be performed
|
2020-04-27 13:34:52 +00:00
|
|
|
authenticated = example.metadata.fetch(:authenticated, true)
|
|
|
|
next if authenticated.blank?
|
2018-12-19 14:47:15 +00:00
|
|
|
|
2020-04-27 13:34:52 +00:00
|
|
|
if authenticated.is_a?(Proc)
|
|
|
|
user = instance_exec(&authenticated)
|
|
|
|
password = user.password_plain
|
|
|
|
|
2020-04-30 14:20:31 +00:00
|
|
|
if password.blank?
|
|
|
|
password = 'automagically set by your friendly capybara helper'
|
|
|
|
user.update!(password: password)
|
|
|
|
end
|
2020-04-27 13:34:52 +00:00
|
|
|
|
|
|
|
credentials = {
|
|
|
|
username: user.email,
|
|
|
|
password: password,
|
|
|
|
}
|
|
|
|
else
|
|
|
|
credentials = {
|
|
|
|
username: 'master@example.com',
|
|
|
|
password: 'test',
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
login(credentials)
|
2018-12-19 14:47:15 +00:00
|
|
|
end
|
|
|
|
end
|