factories.rb 3.81 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 33 34 35 36 37
    trait :two_factor do
      before(:create) do |user|
        user.otp_required_for_login = true
        user.otp_secret = User.generate_otp_secret
      end
    end

38 39 40 41 42 43 44 45 46 47 48 49
    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
50 51
    end

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

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

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

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

  factory :issue do
    title
    author
    project

    trait :closed do
Andrew8xx8's avatar
Andrew8xx8 committed
79 80 81 82 83
      state :closed
    end

    trait :reopened do
      state :reopened
84 85 86
    end

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

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

  factory :key do
    title
Robert Speicher's avatar
Robert Speicher committed
101
    key do
102
      "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0="
Robert Speicher's avatar
Robert Speicher committed
103
    end
104

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

    factory :personal_key do
      user
    end
111

112 113 114 115
    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
116 117 118

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

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

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

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

    trait :closed do
      state :closed
    end

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

  factory :system_hook do
    url
  end

  factory :project_hook do
    url
  end

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

Andrew8xx8's avatar
Andrew8xx8 committed
162 163 164 165 166 167 168
  factory :personal_snippet do
    author
    title
    content
    file_name
  end

169 170 171 172 173 174 175
  factory :snippet do
    author
    title
    content
    file_name
  end

176 177 178
  factory :protected_branch do
    name
    project
179
  end
180 181 182 183 184 185 186 187 188 189 190

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

  factory :service_hook do
    url
    service
  end
191 192 193 194 195

  factory :deploy_keys_project do
    deploy_key
    project
  end
196 197 198 199 200

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