2019-07-25 01:11:48 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-12-13 19:13:44 -05:00
|
|
|
FactoryBot.define do
|
2017-08-09 05:31:25 -04:00
|
|
|
factory :user, aliases: [:author, :assignee, :recipient, :owner, :resource_owner] do
|
2017-03-23 09:08:39 -04:00
|
|
|
email { generate(:email) }
|
|
|
|
name { generate(:name) }
|
|
|
|
username { generate(:username) }
|
2016-02-16 22:55:24 -05:00
|
|
|
password "12345678"
|
|
|
|
confirmed_at { Time.now }
|
|
|
|
confirmation_token { nil }
|
|
|
|
can_create_group true
|
|
|
|
|
2017-08-08 15:54:13 -04:00
|
|
|
after(:stub) do |user|
|
|
|
|
user.notification_email = user.email
|
|
|
|
end
|
|
|
|
|
2016-02-16 22:55:24 -05:00
|
|
|
trait :admin do
|
|
|
|
admin true
|
|
|
|
end
|
|
|
|
|
2017-02-01 13:21:28 -05:00
|
|
|
trait :blocked do
|
|
|
|
after(:build) { |user, _| user.block! }
|
|
|
|
end
|
|
|
|
|
|
|
|
trait :external do
|
|
|
|
external true
|
|
|
|
end
|
|
|
|
|
2016-02-16 22:55:24 -05:00
|
|
|
trait :two_factor do
|
2016-06-06 00:38:42 -04:00
|
|
|
two_factor_via_otp
|
|
|
|
end
|
|
|
|
|
2017-02-06 07:07:05 -05:00
|
|
|
trait :ghost do
|
|
|
|
ghost true
|
2017-02-17 09:58:12 -05:00
|
|
|
after(:build) { |user, _| user.block! }
|
2017-02-06 07:07:05 -05:00
|
|
|
end
|
|
|
|
|
2017-05-03 11:25:31 -04:00
|
|
|
trait :with_avatar do
|
2018-02-01 14:24:59 -05:00
|
|
|
avatar { fixture_file_upload('spec/fixtures/dk.png') }
|
2017-05-03 11:25:31 -04:00
|
|
|
end
|
|
|
|
|
2016-06-06 00:38:42 -04:00
|
|
|
trait :two_factor_via_otp do
|
2016-02-16 22:55:24 -05:00
|
|
|
before(:create) do |user|
|
2016-06-06 00:38:42 -04:00
|
|
|
user.otp_required_for_login = true
|
2016-02-16 22:55:24 -05:00
|
|
|
user.otp_secret = User.generate_otp_secret(32)
|
|
|
|
user.otp_grace_period_started_at = Time.now
|
|
|
|
user.generate_otp_backup_codes!
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-06 00:38:42 -04:00
|
|
|
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
|
|
|
|
|
2017-11-21 12:58:42 -05:00
|
|
|
trait :readme do
|
|
|
|
project_view :readme
|
|
|
|
end
|
|
|
|
|
2018-09-17 09:14:58 -04:00
|
|
|
trait :commit_email do
|
|
|
|
after(:create) do |user, evaluator|
|
|
|
|
additional = create(:email, :confirmed, user: user, email: "commit-#{user.email}")
|
|
|
|
|
|
|
|
user.update!(commit_email: additional.email)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-04-11 11:21:18 -04:00
|
|
|
transient do
|
|
|
|
developer_projects []
|
|
|
|
end
|
|
|
|
|
|
|
|
after(:create) do |user, evaluator|
|
|
|
|
evaluator.developer_projects.each do |project|
|
|
|
|
project.add_developer(user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-16 22:55:24 -05:00
|
|
|
factory :omniauth_user do
|
|
|
|
transient do
|
|
|
|
extern_uid '123456'
|
|
|
|
provider 'ldapmain'
|
|
|
|
end
|
|
|
|
|
|
|
|
after(:create) do |user, evaluator|
|
2019-02-14 12:56:34 -05:00
|
|
|
identity_attrs = {
|
2016-02-16 22:55:24 -05:00
|
|
|
provider: evaluator.provider,
|
|
|
|
extern_uid: evaluator.extern_uid
|
2019-02-14 12:56:34 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if evaluator.respond_to?(:saml_provider)
|
|
|
|
identity_attrs[:saml_provider] = evaluator.saml_provider
|
|
|
|
end
|
|
|
|
|
|
|
|
user.identities << create(:identity, identity_attrs)
|
2016-02-16 22:55:24 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
factory :admin, traits: [:admin]
|
|
|
|
end
|
|
|
|
end
|