2020-01-03 10:44:06 +09:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module ProfileStories
|
2024-10-23 22:31:03 +09:00
|
|
|
attr_reader :bob
|
2020-01-03 10:44:06 +09:00
|
|
|
|
2024-07-29 17:31:42 +09:00
|
|
|
def fill_in_auth_details(email, password)
|
|
|
|
fill_in 'user_email', with: email
|
|
|
|
fill_in 'user_password', with: password
|
|
|
|
click_on I18n.t('auth.login')
|
|
|
|
end
|
|
|
|
|
2020-01-03 10:44:06 +09:00
|
|
|
def as_a_registered_user
|
|
|
|
@bob = Fabricate(
|
|
|
|
:user,
|
|
|
|
email: email, password: password, confirmed_at: confirmed_at,
|
|
|
|
account: Fabricate(:account, username: 'bob')
|
|
|
|
)
|
2023-07-29 06:09:49 +09:00
|
|
|
|
2024-01-31 00:38:33 +09:00
|
|
|
Web::Setting.where(user: bob).first_or_initialize(user: bob).update!(data: { introductionVersion: 2018_12_16_044202 }) if finished_onboarding
|
2020-01-03 10:44:06 +09:00
|
|
|
end
|
|
|
|
|
|
|
|
def as_a_logged_in_user
|
|
|
|
as_a_registered_user
|
|
|
|
visit new_user_session_path
|
2024-07-29 17:31:42 +09:00
|
|
|
fill_in_auth_details(email, password)
|
2020-01-03 10:44:06 +09:00
|
|
|
end
|
|
|
|
|
2024-02-28 00:18:06 +09:00
|
|
|
def as_a_logged_in_admin
|
|
|
|
# This is a bit awkward, but this avoids code duplication.
|
|
|
|
as_a_logged_in_user
|
|
|
|
bob.update!(role: UserRole.find_by!(name: 'Admin'))
|
|
|
|
end
|
|
|
|
|
2020-01-03 10:44:06 +09:00
|
|
|
def confirmed_at
|
|
|
|
@confirmed_at ||= Time.zone.now
|
|
|
|
end
|
|
|
|
|
|
|
|
def email
|
|
|
|
@email ||= 'test@example.com'
|
|
|
|
end
|
|
|
|
|
|
|
|
def password
|
|
|
|
@password ||= 'password'
|
|
|
|
end
|
2023-07-29 06:09:49 +09:00
|
|
|
|
|
|
|
def finished_onboarding
|
|
|
|
@finished_onboarding || false
|
|
|
|
end
|
2020-01-03 10:44:06 +09:00
|
|
|
end
|