BigW Consortium Gitlab

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

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

8
  sequence :name do
9 10 11
    Faker::Name.name
  end

12 13 14 15
  sequence :file_name do
    Faker::Internet.user_name
  end

16 17
  sequence(:url) { Faker::Internet.uri('http') }

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

    trait :admin do
      admin true
    end

31 32 33 34 35 36 37 38 39 40 41 42
    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
43 44
    end

45 46 47
    factory :admin, traits: [:admin]
  end

Dmitriy Zaporozhets committed
48
  factory :group do
49
    sequence(:name) { |n| "group#{n}" }
50
    path { name.downcase.gsub(/\s/, '_') }
Dmitriy Zaporozhets committed
51 52
    type 'Group'
  end
53

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

60
  factory :project_member do
61 62
    user
    project
63
    access_level { ProjectMember::MASTER }
64 65 66 67 68 69 70 71
  end

  factory :issue do
    title
    author
    project

    trait :closed do
Andrew8xx8 committed
72 73 74 75 76
      state :closed
    end

    trait :reopened do
      state :reopened
77 78 79
    end

    factory :closed_issue, traits: [:closed]
Andrew8xx8 committed
80
    factory :reopened_issue, traits: [:reopened]
81 82 83
  end

  factory :event do
randx committed
84 85
    factory :closed_issue_event do
      project
86
      action { Event::CLOSED }
randx committed
87 88 89
      target factory: :closed_issue
      author factory: :user
    end
90 91 92 93
  end

  factory :key do
    title
Robert Speicher committed
94
    key do
95
      "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0="
Robert Speicher committed
96
    end
97

98
    factory :deploy_key, class: 'DeployKey' do
99 100 101 102 103
    end

    factory :personal_key do
      user
    end
104 105 106 107 108 109

    factory :key_with_a_space_in_the_middle do
      key do
        "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa ++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0="
      end
    end
110

111 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
    end

117 118 119 120 121
    factory :invalid_key do
      key do
        "ssh-rsa this_is_invalid_key=="
      end
    end
122
  end
123

124 125 126 127 128 129 130 131 132 133 134 135
  factory :email do
    user
    email do
      Faker::Internet.email('alias')
    end

    factory :another_email do
      email do
        Faker::Internet.email('another.alias')
      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

164 165 166 167 168 169 170
  factory :personal_snippet do
    author
    title
    content
    file_name
  end

171 172 173 174 175 176 177
  factory :snippet do
    author
    title
    content
    file_name
  end

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

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

  factory :service_hook do
    url
    service
  end
193 194 195 196 197

  factory :deploy_keys_project do
    deploy_key
    project
  end
198 199 200 201 202

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