BigW Consortium Gitlab

factories.rb 4.12 KB
Newer Older
Jack Weeden committed
1 2
include ActionDispatch::TestProcess

3 4
FactoryGirl.define do
  sequence :sentence, aliases: [:title, :content] do
Robert Speicher committed
5
    FFaker::Lorem.sentence
6 7
  end

8
  sequence :name do
Robert Speicher committed
9
    FFaker::Name.name
10 11
  end

12
  sequence :file_name do
Robert Speicher committed
13
    FFaker::Internet.user_name
14 15
  end

Robert Speicher committed
16
  sequence(:url) { FFaker::Internet.uri('http') }
17

18
  factory :user, aliases: [:author, :assignee, :owner, :creator] do
Robert Speicher committed
19
    email { FFaker::Internet.email }
20
    name
Robert Speicher committed
21
    sequence(:username) { |n| "#{FFaker::Internet.user_name}#{n}" }
22
    password "12345678"
Dmitriy Zaporozhets committed
23
    confirmed_at { Time.now }
24
    confirmation_token { nil }
25
    can_create_group true
26 27 28 29 30

    trait :admin do
      admin true
    end

31 32
    trait :two_factor do
      before(:create) do |user|
33
        user.two_factor_enabled = true
34
        user.otp_secret = User.generate_otp_secret(32)
35
        user.generate_otp_backup_codes!
36 37 38
      end
    end

39 40 41 42 43 44 45 46 47 48 49 50
    factory :omniauth_user do
      ignore 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
51 52
    end

53 54 55
    factory :admin, traits: [:admin]
  end

Dmitriy Zaporozhets committed
56
  factory :group do
57
    sequence(:name) { |n| "group#{n}" }
58
    path { name.downcase.gsub(/\s/, '_') }
Dmitriy Zaporozhets committed
59 60
    type 'Group'
  end
61

Dmitriy Zaporozhets committed
62
  factory :namespace do
63
    sequence(:name) { |n| "namespace#{n}" }
Dmitriy Zaporozhets committed
64 65
    path { name.downcase.gsub(/\s/, '_') }
    owner
66 67
  end

68
  factory :project_member do
69 70
    user
    project
71
    access_level { ProjectMember::MASTER }
72 73 74 75 76 77 78 79
  end

  factory :issue do
    title
    author
    project

    trait :closed do
Andrew8xx8 committed
80 81 82 83 84
      state :closed
    end

    trait :reopened do
      state :reopened
85 86 87
    end

    factory :closed_issue, traits: [:closed]
Andrew8xx8 committed
88
    factory :reopened_issue, traits: [:reopened]
89 90 91
  end

  factory :event do
randx committed
92 93
    factory :closed_issue_event do
      project
94
      action { Event::CLOSED }
randx committed
95 96 97
      target factory: :closed_issue
      author factory: :user
    end
98 99 100 101
  end

  factory :key do
    title
Robert Speicher committed
102
    key do
103
      "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0= dummy@gitlab.com"
Robert Speicher committed
104
    end
105

106
    factory :deploy_key, class: 'DeployKey' do
107 108 109 110 111
    end

    factory :personal_key do
      user
    end
112

113 114 115 116
    factory :another_key do
      key do
        "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDmTillFzNTrrGgwaCKaSj+QCz81E6jBc/s9av0+3b1Hwfxgkqjl4nAK/OD2NjgyrONDTDfR8cRN4eAAy6nY8GLkOyYBDyuc5nTMqs5z3yVuTwf3koGm/YQQCmo91psZ2BgDFTor8SVEE5Mm1D1k3JDMhDFxzzrOtRYFPci9lskTJaBjpqWZ4E9rDTD2q/QZntCqbC3wE9uSemRQB5f8kik7vD/AD8VQXuzKladrZKkzkONCPWsXDspUitjM8HkQdOf0PsYn1CMUC1xKYbCxkg5TkEosIwGv6CoEArUrdu/4+10LVslq494mAvEItywzrluCLCnwELfW+h/m8UHoVhZ"
      end
117 118 119

      factory :another_deploy_key, class: 'DeployKey' do
      end
120
    end
121
  end
122

123 124 125
  factory :email do
    user
    email do
Robert Speicher committed
126
      FFaker::Internet.email('alias')
127 128 129 130
    end

    factory :another_email do
      email do
Robert Speicher committed
131
        FFaker::Internet.email('another.alias')
132 133 134
      end
    end
  end
135 136 137 138

  factory :milestone do
    title
    project
139 140 141 142 143 144

    trait :closed do
      state :closed
    end

    factory :closed_milestone, traits: [:closed]
145 146 147 148 149 150 151 152 153 154
  end

  factory :system_hook do
    url
  end

  factory :project_hook do
    url
  end

155
  factory :project_snippet do
156 157 158 159
    project
    author
    title
    content
160 161 162
    file_name
  end

163 164 165 166 167
  factory :personal_snippet do
    author
    title
    content
    file_name
168 169 170 171 172 173 174 175 176 177 178 179

    trait :public do
      visibility_level Gitlab::VisibilityLevel::PUBLIC
    end

    trait :internal do
      visibility_level Gitlab::VisibilityLevel::INTERNAL
    end

    trait :private do
      visibility_level Gitlab::VisibilityLevel::PRIVATE
    end
180 181
  end

182 183 184 185 186 187 188
  factory :snippet do
    author
    title
    content
    file_name
  end

189 190 191
  factory :protected_branch do
    name
    project
192
  end
193 194 195 196 197 198 199 200 201 202 203

  factory :service do
    type ""
    title "GitLab CI"
    project
  end

  factory :service_hook do
    url
    service
  end
204 205 206 207 208

  factory :deploy_keys_project do
    deploy_key
    project
  end
209 210 211 212 213

  factory :identity do
    provider 'ldapmain'
    extern_uid 'my-ldap-id'
  end
214
end