BigW Consortium Gitlab

users.rb 1.77 KB
Newer Older
1
FactoryBot.define do
2
  factory :user, aliases: [:author, :assignee, :recipient, :owner, :resource_owner] do
3 4 5
    email { generate(:email) }
    name { generate(:name) }
    username { generate(:username) }
6 7 8 9 10
    password "12345678"
    confirmed_at { Time.now }
    confirmation_token { nil }
    can_create_group true

11 12 13 14
    after(:stub) do |user|
      user.notification_email = user.email
    end

15 16 17 18
    before(:create) do |user|
      user.ensure_rss_token
    end

19 20 21 22
    trait :admin do
      admin true
    end

23 24 25 26 27 28 29 30
    trait :blocked do
      after(:build) { |user, _| user.block! }
    end

    trait :external do
      external true
    end

31
    trait :two_factor do
32 33 34
      two_factor_via_otp
    end

35 36
    trait :ghost do
      ghost true
37
      after(:build) { |user, _| user.block! }
38 39
    end

40
    trait :with_avatar do
41
      avatar { fixture_file_upload('spec/fixtures/dk.png') }
42 43
    end

44
    trait :two_factor_via_otp do
45
      before(:create) do |user|
46
        user.otp_required_for_login = true
47 48 49 50 51 52
        user.otp_secret = User.generate_otp_secret(32)
        user.otp_grace_period_started_at = Time.now
        user.generate_otp_backup_codes!
      end
    end

53 54 55 56 57 58 59 60
    trait :two_factor_via_u2f do
      transient { registrations_count 5 }

      after(:create) do |user, evaluator|
        create_list(:u2f_registration, evaluator.registrations_count, user: user)
      end
    end

61 62 63 64
    trait :readme do
      project_view :readme
    end

65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
    factory :omniauth_user do
      transient do
        extern_uid '123456'
        provider 'ldapmain'
      end

      after(:create) do |user, evaluator|
        user.identities << create(
          :identity,
          provider: evaluator.provider,
          extern_uid: evaluator.extern_uid
        )
      end
    end

    factory :admin, traits: [:admin]
  end
end