factories.rb 4.75 KB
Newer Older
1 2 3 4 5
FactoryGirl.define do
  sequence :sentence, aliases: [:title, :content] do
    Faker::Lorem.sentence
  end

6 7 8 9
  sequence :name, aliases: [:file_name] do
    Faker::Name.name
  end

10 11
  sequence(:url) { Faker::Internet.uri('http') }

12
  factory :user, aliases: [:author, :assignee, :owner, :creator] do
13
    email { Faker::Internet.email }
14
    name
15
    sequence(:username) { |n| "#{Faker::Internet.user_name}#{n}" }
16
    password "123456"
17
    password_confirmation { password }
18 19 20 21 22 23 24 25 26 27

    trait :admin do
      admin true
    end

    factory :admin, traits: [:admin]
  end

  factory :project do
    sequence(:name) { |n| "project#{n}" }
28
    path { name.downcase.gsub(/\s/, '_') }
29
    creator
30 31
  end

32 33
  factory :redmine_project, parent: :project do
    issues_tracker { "redmine" }
Andrew8xx8's avatar
Andrew8xx8 committed
34
    issues_tracker_id { "project_name_in_redmine" }
35 36
  end

37 38 39 40
  factory :project_with_code, parent: :project do
    path { 'gitlabhq' }
  end

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

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

54 55 56
  factory :users_project do
    user
    project
57
    project_access { UsersProject::MASTER }
58 59 60 61 62 63 64 65
  end

  factory :issue do
    title
    author
    project

    trait :closed do
Andrew8xx8's avatar
Andrew8xx8 committed
66 67 68 69 70
      state :closed
    end

    trait :reopened do
      state :reopened
71 72 73
    end

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

  factory :merge_request do
    title
    author
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
80
    project factory: :project_with_code
81 82
    source_branch "master"
    target_branch "stable"
83

84 85
    # pick 3 commits "at random" (from bcf03b5d~3 to bcf03b5d)
    trait :with_diffs do
Riyad Preukschas's avatar
Riyad Preukschas committed
86 87
      target_branch "master" # pretend bcf03b5d~3
      source_branch "stable" # pretend bcf03b5d
88
      st_commits do
89 90 91 92 93
        [
          project.repository.commit('bcf03b5d').to_hash,
          project.repository.commit('bcf03b5d~1').to_hash,
          project.repository.commit('bcf03b5d~2').to_hash
        ]
94 95 96 97 98 99
      end
      st_diffs do
        project.repo.diff("bcf03b5d~3", "bcf03b5d")
      end
    end

100 101 102 103 104 105 106 107
    trait :closed do
      state :closed
    end

    trait :reopened do
      state :reopened
    end

108
    factory :closed_merge_request, traits: [:closed]
109
    factory :reopened_merge_request, traits: [:reopened]
110
    factory :merge_request_with_diffs, traits: [:with_diffs]
111 112 113 114 115
  end

  factory :note do
    project
    note "Note"
Riyad Preukschas's avatar
Riyad Preukschas committed
116 117 118
    author

    factory :note_on_commit, traits: [:on_commit]
Riyad Preukschas's avatar
Riyad Preukschas committed
119
    factory :note_on_commit_diff, traits: [:on_commit, :on_diff]
Riyad Preukschas's avatar
Riyad Preukschas committed
120 121
    factory :note_on_issue, traits: [:on_issue], aliases: [:votable_note]
    factory :note_on_merge_request, traits: [:on_merge_request]
Riyad Preukschas's avatar
Riyad Preukschas committed
122
    factory :note_on_merge_request_diff, traits: [:on_merge_request, :on_diff]
Riyad Preukschas's avatar
Riyad Preukschas committed
123 124

    trait :on_commit do
125
      project factory: :project_with_code
126
      commit_id     "bcf03b5de6c33f3869ef70d68cf06e679d1d7f9a"
Riyad Preukschas's avatar
Riyad Preukschas committed
127 128 129
      noteable_type "Commit"
    end

Riyad Preukschas's avatar
Riyad Preukschas committed
130
    trait :on_diff do
Riyad Preukschas's avatar
Riyad Preukschas committed
131 132 133 134
      line_code "0_184_184"
    end

    trait :on_merge_request do
135
      project factory: :project_with_code
Riyad Preukschas's avatar
Riyad Preukschas committed
136 137 138 139 140
      noteable_id   1
      noteable_type "MergeRequest"
    end

    trait :on_issue do
141
      noteable_id   1
Riyad Preukschas's avatar
Riyad Preukschas committed
142 143
      noteable_type "Issue"
    end
144 145 146
  end

  factory :event do
randx's avatar
randx committed
147 148
    factory :closed_issue_event do
      project
149
      action { Event::CLOSED }
randx's avatar
randx committed
150 151 152
      target factory: :closed_issue
      author factory: :user
    end
153 154 155 156
  end

  factory :key do
    title
Robert Speicher's avatar
Robert Speicher committed
157
    key do
158
      "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0="
Robert Speicher's avatar
Robert Speicher committed
159
    end
160

161
    factory :deploy_key, class: 'DeployKey' do
162 163 164 165 166
    end

    factory :personal_key do
      user
    end
167 168 169 170 171 172

    factory :key_with_a_space_in_the_middle do
      key do
        "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa ++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0="
      end
    end
173 174 175 176 177 178

    factory :invalid_key do
      key do
        "ssh-rsa this_is_invalid_key=="
      end
    end
179 180 181 182 183
  end

  factory :milestone do
    title
    project
184 185 186 187 188 189

    trait :closed do
      state :closed
    end

    factory :closed_milestone, traits: [:closed]
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
  end

  factory :system_hook do
    url
  end

  factory :project_hook do
    url
  end

  factory :snippet do
    project
    author
    title
    content
205 206 207 208 209 210
    file_name
  end

  factory :protected_branch do
    name
    project
211
  end
212 213 214 215 216 217 218 219 220 221 222 223

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

  factory :service_hook do
    url
    service
  end
224 225 226 227 228

  factory :deploy_keys_project do
    deploy_key
    project
  end
229
end