profile_stories.rb 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # frozen_string_literal: true
  2. module ProfileStories
  3. attr_reader :bob, :alice, :alice_bio
  4. def as_a_registered_user
  5. @bob = Fabricate(
  6. :user,
  7. email: email, password: password, confirmed_at: confirmed_at,
  8. account: Fabricate(:account, username: 'bob')
  9. )
  10. Web::Setting.where(user: bob).first_or_initialize(user: bob).update!(data: { introductionVersion: 2018_12_16_044202 }) if finished_onboarding
  11. end
  12. def as_a_logged_in_user
  13. as_a_registered_user
  14. visit new_user_session_path
  15. fill_in 'user_email', with: email
  16. fill_in 'user_password', with: password
  17. click_on I18n.t('auth.login')
  18. end
  19. def as_a_logged_in_admin
  20. # This is a bit awkward, but this avoids code duplication.
  21. as_a_logged_in_user
  22. bob.update!(role: UserRole.find_by!(name: 'Admin'))
  23. end
  24. def with_alice_as_local_user
  25. @alice_bio = '@alice and @bob are fictional characters commonly used as' \
  26. 'placeholder names in #cryptology, as well as #science and' \
  27. 'engineering 📖 literature. Not affiliated with @pepe.'
  28. @alice = Fabricate(
  29. :user,
  30. email: 'alice@example.com', password: password, confirmed_at: confirmed_at,
  31. account: Fabricate(:account, username: 'alice', note: @alice_bio)
  32. )
  33. end
  34. def confirmed_at
  35. @confirmed_at ||= Time.zone.now
  36. end
  37. def email
  38. @email ||= 'test@example.com'
  39. end
  40. def password
  41. @password ||= 'password'
  42. end
  43. def finished_onboarding
  44. @finished_onboarding || false
  45. end
  46. end