profile_stories.rb 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. # frozen_string_literal: true
  2. module ProfileStories
  3. attr_reader :bob
  4. def fill_in_auth_details(email, password)
  5. fill_in 'user_email', with: email
  6. fill_in 'user_password', with: password
  7. click_on I18n.t('auth.login')
  8. end
  9. def as_a_registered_user
  10. @bob = Fabricate(
  11. :user,
  12. email: email, password: password, confirmed_at: confirmed_at,
  13. account: Fabricate(:account, username: 'bob')
  14. )
  15. Web::Setting.where(user: bob).first_or_initialize(user: bob).update!(data: { introductionVersion: 2018_12_16_044202 }) if finished_onboarding
  16. end
  17. def as_a_logged_in_user
  18. as_a_registered_user
  19. visit new_user_session_path
  20. fill_in_auth_details(email, password)
  21. end
  22. def as_a_logged_in_admin
  23. # This is a bit awkward, but this avoids code duplication.
  24. as_a_logged_in_user
  25. bob.update!(role: UserRole.find_by!(name: 'Admin'))
  26. end
  27. def confirmed_at
  28. @confirmed_at ||= Time.zone.now
  29. end
  30. def email
  31. @email ||= 'test@example.com'
  32. end
  33. def password
  34. @password ||= 'password'
  35. end
  36. def finished_onboarding
  37. @finished_onboarding || false
  38. end
  39. end