2018-03-17 18:26:18 +05:30
|
|
|
FactoryBot.define do
|
|
|
|
factory :user, aliases: [:author, :assignee, :recipient, :owner, :resource_owner] do
|
2017-08-17 22:00:37 +05:30
|
|
|
email { generate(:email) }
|
|
|
|
name { generate(:name) }
|
|
|
|
username { generate(:username) }
|
2016-06-02 11:05:42 +05:30
|
|
|
password "12345678"
|
|
|
|
confirmed_at { Time.now }
|
|
|
|
confirmation_token { nil }
|
|
|
|
can_create_group true
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
after(:stub) do |user|
|
|
|
|
user.notification_email = user.email
|
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
trait :admin do
|
|
|
|
admin true
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
trait :blocked do
|
|
|
|
after(:build) { |user, _| user.block! }
|
|
|
|
end
|
|
|
|
|
|
|
|
trait :external do
|
|
|
|
external true
|
|
|
|
end
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
trait :two_factor do
|
2016-06-16 23:09:34 +05:30
|
|
|
two_factor_via_otp
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
trait :ghost do
|
|
|
|
ghost true
|
|
|
|
after(:build) { |user, _| user.block! }
|
|
|
|
end
|
|
|
|
|
|
|
|
trait :with_avatar do
|
2018-03-17 18:26:18 +05:30
|
|
|
avatar { fixture_file_upload('spec/fixtures/dk.png') }
|
2017-08-17 22:00:37 +05:30
|
|
|
end
|
|
|
|
|
2016-06-16 23:09:34 +05:30
|
|
|
trait :two_factor_via_otp do
|
2016-06-02 11:05:42 +05:30
|
|
|
before(:create) do |user|
|
2016-06-16 23:09:34 +05:30
|
|
|
user.otp_required_for_login = true
|
2016-06-02 11:05:42 +05:30
|
|
|
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-16 23:09:34 +05:30
|
|
|
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
|
|
|
|
|
2018-03-17 18:26:18 +05:30
|
|
|
trait :readme do
|
|
|
|
project_view :readme
|
|
|
|
end
|
|
|
|
|
2018-12-05 23:21:45 +05:30
|
|
|
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
|
|
|
|
|
2016-06-02 11:05:42 +05:30
|
|
|
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
|