factories.rb 4.13 KB
Newer Older
Jack Weeden's avatar
Jack Weeden committed
1 2
include ActionDispatch::TestProcess

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

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
8
  sequence :name do
Robert Speicher's avatar
Robert Speicher committed
9
    FFaker::Name.name
10 11
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
12
  sequence :file_name do
Robert Speicher's avatar
Robert Speicher committed
13
    FFaker::Internet.user_name
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
14 15
  end

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

18
  factory :user, aliases: [:author, :assignee, :owner, :creator] do
Robert Speicher's avatar
Robert Speicher committed
19
    email { FFaker::Internet.email }
20
    name
Robert Speicher's avatar
Robert Speicher committed
21
    sequence(:username) { |n| "#{FFaker::Internet.user_name}#{n}" }
22
    password "12345678"
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
23
    confirmed_at { Time.now }
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
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
    factory :omniauth_user do
      ignore do
        extern_uid '123456'
        provider 'ldapmain'
      end

      after(:create) do |user, evaluator|
Gabriel Mazetto's avatar
Gabriel Mazetto committed
46 47
        user.identities << create(
          :identity,
48 49 50 51
          provider: evaluator.provider,
          extern_uid: evaluator.extern_uid
        )
      end
52 53
    end

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

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

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

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

  factory :issue do
    title
    author
    project

    trait :closed do
Andrew8xx8's avatar
Andrew8xx8 committed
81 82 83 84 85
      state :closed
    end

    trait :reopened do
      state :reopened
86 87 88
    end

    factory :closed_issue, traits: [:closed]
Andrew8xx8's avatar
Andrew8xx8 committed
89
    factory :reopened_issue, traits: [:reopened]
90 91 92
  end

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

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

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

    factory :personal_key do
      user
    end
113

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

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

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

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

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

    trait :closed do
      state :closed
    end

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

  factory :system_hook do
    url
  end

  factory :project_hook do
    url
  end

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

Andrew8xx8's avatar
Andrew8xx8 committed
164 165 166 167 168
  factory :personal_snippet do
    author
    title
    content
    file_name
169 170 171 172 173 174 175 176 177 178 179 180

    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
Andrew8xx8's avatar
Andrew8xx8 committed
181 182
  end

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

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

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

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

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

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