factories.rb 3.94 KB
Newer Older
Jack Weeden's avatar
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 9 10 11
  sequence :name, aliases: [:file_name] do
    Faker::Name.name
  end

12 13
  sequence(:url) { Faker::Internet.uri('http') }

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

    trait :admin do
      admin true
    end

27 28 29 30 31 32 33 34 35 36 37 38
    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
39 40
    end

41 42 43
    factory :admin, traits: [:admin]
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
44
  factory :group do
45
    sequence(:name) { |n| "group#{n}" }
46
    path { name.downcase.gsub(/\s/, '_') }
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
47 48
    type 'Group'
  end
49

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
50
  factory :namespace do
51
    sequence(:name) { |n| "namespace#{n}" }
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
52 53
    path { name.downcase.gsub(/\s/, '_') }
    owner
54 55
  end

56
  factory :project_member do
57 58
    user
    project
59
    access_level { ProjectMember::MASTER }
60 61 62 63 64 65 66 67
  end

  factory :issue do
    title
    author
    project

    trait :closed do
Andrew8xx8's avatar
Andrew8xx8 committed
68 69 70 71 72
      state :closed
    end

    trait :reopened do
      state :reopened
73 74 75
    end

    factory :closed_issue, traits: [:closed]
Andrew8xx8's avatar
Andrew8xx8 committed
76
    factory :reopened_issue, traits: [:reopened]
77 78 79
  end

  factory :event do
randx's avatar
randx committed
80 81
    factory :closed_issue_event do
      project
82
      action { Event::CLOSED }
randx's avatar
randx committed
83 84 85
      target factory: :closed_issue
      author factory: :user
    end
86 87 88 89
  end

  factory :key do
    title
Robert Speicher's avatar
Robert Speicher committed
90
    key do
91
      "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0="
Robert Speicher's avatar
Robert Speicher committed
92
    end
93

94
    factory :deploy_key, class: 'DeployKey' do
95 96 97 98 99
    end

    factory :personal_key do
      user
    end
100 101 102 103 104 105

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

107 108 109 110 111 112
    factory :another_key do
      key do
        "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDmTillFzNTrrGgwaCKaSj+QCz81E6jBc/s9av0+3b1Hwfxgkqjl4nAK/OD2NjgyrONDTDfR8cRN4eAAy6nY8GLkOyYBDyuc5nTMqs5z3yVuTwf3koGm/YQQCmo91psZ2BgDFTor8SVEE5Mm1D1k3JDMhDFxzzrOtRYFPci9lskTJaBjpqWZ4E9rDTD2q/QZntCqbC3wE9uSemRQB5f8kik7vD/AD8VQXuzKladrZKkzkONCPWsXDspUitjM8HkQdOf0PsYn1CMUC1xKYbCxkg5TkEosIwGv6CoEArUrdu/4+10LVslq494mAvEItywzrluCLCnwELfW+h/m8UHoVhZ"
      end
    end

113 114 115 116 117
    factory :invalid_key do
      key do
        "ssh-rsa this_is_invalid_key=="
      end
    end
118
  end
119

120 121 122 123 124 125 126 127 128 129 130 131
  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
132 133 134 135

  factory :milestone do
    title
    project
136 137 138 139 140 141

    trait :closed do
      state :closed
    end

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

  factory :system_hook do
    url
  end

  factory :project_hook do
    url
  end

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

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

167 168 169 170 171 172 173
  factory :snippet do
    author
    title
    content
    file_name
  end

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

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

  factory :service_hook do
    url
    service
  end
189 190 191 192 193

  factory :deploy_keys_project do
    deploy_key
    project
  end
194 195 196 197 198

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