X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/737a325f2e4b45b26277de7986325705ff17b63d..8fb45ef0fddee05d8fa3829303f61226764bd91a:/test/factories/user.rb diff --git a/test/factories/user.rb b/test/factories/user.rb index a7219324a..166461637 100644 --- a/test/factories/user.rb +++ b/test/factories/user.rb @@ -1,8 +1,18 @@ -FactoryGirl.define do +FactoryBot.define do factory :user do sequence(:email) { |n| "user#{n}@example.com" } sequence(:display_name) { |n| "User #{n}" } - pass_crypt Digest::MD5.hexdigest("test") + pass_crypt { Digest::MD5.hexdigest("test") } + + # These attributes are not the defaults, but in most tests we want + # a 'normal' user who can log in without being redirected etc. + after(:build) do |user, _evaluator| + user.activate + end + + terms_seen { true } + terms_agreed { Time.now.utc } + data_public { true } trait :with_home_location do home_lat { rand(-90.0...90.0) } @@ -10,23 +20,37 @@ FactoryGirl.define do end trait :pending do - status "pending" + after(:build) do |user, _evaluator| + user.deactivate + end end trait :active do - status "active" + # status { "active" } end trait :confirmed do - status "confirmed" + after(:build) do |user, _evaluator| + user.confirm + end end trait :suspended do - status "suspended" + after(:build) do |user, _evaluator| + user.suspend + end end trait :deleted do - status "deleted" + after(:build) do |user, _evaluator| + user.soft_destroy + end + end + + factory :importer_user do + after(:create) do |user, _evaluator| + create(:user_role, :role => "importer", :user => user) + end end factory :moderator_user do @@ -41,11 +65,12 @@ FactoryGirl.define do end end - # A commonly needed user is one who can log in an isn't redirected anywhere - factory :normal_user do - status "active" - terms_seen true - data_public true + factory :super_user do + after(:create) do |user, _evaluator| + UserRole::ALL_ROLES.each do |role| + create(:user_role, :role => role, :user => user) + end + end end end end