user.rb 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 do
  21. role_ids { Role.signup_role_ids.sort }
  22. trait :with_org do
  23. organization
  24. end
  25. end
  26. factory :agent_and_customer do
  27. role_ids { Role.signup_role_ids.push( Role.find_by(name: 'Agent').id ).sort }
  28. trait :with_org do
  29. organization
  30. end
  31. end
  32. factory :agent do
  33. roles { Role.where(name: 'Agent') }
  34. end
  35. factory :admin do
  36. roles { Role.where(name: %w[Admin Agent]) }
  37. end
  38. # make given password accessible for e.g. authentication logic
  39. before(:create) do |user|
  40. password_plain = user.password
  41. user.define_singleton_method(:password_plain, -> { password_plain })
  42. end
  43. end
  44. end