user.rb 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. FactoryBot.define do
  2. factory :user do
  3. transient do
  4. intro_clues { true }
  5. end
  6. login { 'nicole.braun' }
  7. firstname { 'Nicole' }
  8. lastname { 'Braun' }
  9. sequence(:email) { |n| "nicole.braun#{n}@zammad.org" }
  10. password { nil }
  11. active { true }
  12. login_failed { 0 }
  13. updated_by_id { 1 }
  14. created_by_id { 1 }
  15. callback(:after_stub, :before_create) do |object, context|
  16. next if !context.intro_clues
  17. object.preferences ||= {}
  18. object.preferences[:intro] = true
  19. end
  20. factory :customer_user, aliases: %i[customer] do
  21. role_ids { Role.signup_role_ids.sort }
  22. trait :with_org do
  23. organization
  24. end
  25. end
  26. factory :agent_user, aliases: %i[agent] do
  27. roles { Role.where(name: 'Agent') }
  28. end
  29. factory :admin_user, aliases: %i[admin] do
  30. roles { Role.where(name: %w[Admin Agent]) }
  31. end
  32. # make given password accessible for e.g. authentication logic
  33. before(:create) do |user|
  34. password_plain = user.password
  35. user.define_singleton_method(:password_plain, -> { password_plain })
  36. end
  37. end
  38. end