factories.rb 4.19 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

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
32
  factory :group do
33
    sequence(:name) { |n| "group#{n}" }
34
    path { name.downcase.gsub(/\s/, '_') }
35
    owner
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
36 37
    type 'Group'
  end
38

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
39
  factory :namespace do
40
    sequence(:name) { |n| "namespace#{n}" }
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
41 42
    path { name.downcase.gsub(/\s/, '_') }
    owner
43 44
  end

45 46 47
  factory :users_project do
    user
    project
48
    project_access { UsersProject::MASTER }
49 50 51 52 53 54 55 56
  end

  factory :issue do
    title
    author
    project

    trait :closed do
Andrew8xx8's avatar
Andrew8xx8 committed
57 58 59 60 61
      state :closed
    end

    trait :reopened do
      state :reopened
62 63 64
    end

    factory :closed_issue, traits: [:closed]
Andrew8xx8's avatar
Andrew8xx8 committed
65
    factory :reopened_issue, traits: [:reopened]
66 67 68 69 70 71 72 73
  end

  factory :merge_request do
    title
    author
    project
    source_branch "master"
    target_branch "stable"
74

75 76
    # pick 3 commits "at random" (from bcf03b5d~3 to bcf03b5d)
    trait :with_diffs do
Riyad Preukschas's avatar
Riyad Preukschas committed
77 78
      target_branch "master" # pretend bcf03b5d~3
      source_branch "stable" # pretend bcf03b5d
79 80 81 82 83 84 85 86 87 88
      st_commits do
        [Commit.new(project.repo.commit('bcf03b5d')),
         Commit.new(project.repo.commit('bcf03b5d~1')),
         Commit.new(project.repo.commit('bcf03b5d~2'))]
      end
      st_diffs do
        project.repo.diff("bcf03b5d~3", "bcf03b5d")
      end
    end

89 90 91 92 93 94 95 96
    trait :closed do
      state :closed
    end

    trait :reopened do
      state :reopened
    end

97
    factory :closed_merge_request, traits: [:closed]
98
    factory :reopened_merge_request, traits: [:reopened]
99
    factory :merge_request_with_diffs, traits: [:with_diffs]
100 101 102 103 104
  end

  factory :note do
    project
    note "Note"
Riyad Preukschas's avatar
Riyad Preukschas committed
105 106 107
    author

    factory :note_on_commit, traits: [:on_commit]
Riyad Preukschas's avatar
Riyad Preukschas committed
108
    factory :note_on_commit_diff, traits: [:on_commit, :on_diff]
Riyad Preukschas's avatar
Riyad Preukschas committed
109 110
    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
111
    factory :note_on_merge_request_diff, traits: [:on_merge_request, :on_diff]
Riyad Preukschas's avatar
Riyad Preukschas committed
112 113

    trait :on_commit do
114
      commit_id     "bcf03b5de6c33f3869ef70d68cf06e679d1d7f9a"
Riyad Preukschas's avatar
Riyad Preukschas committed
115 116 117
      noteable_type "Commit"
    end

Riyad Preukschas's avatar
Riyad Preukschas committed
118
    trait :on_diff do
Riyad Preukschas's avatar
Riyad Preukschas committed
119 120 121 122 123 124 125 126 127
      line_code "0_184_184"
    end

    trait :on_merge_request do
      noteable_id   1
      noteable_type "MergeRequest"
    end

    trait :on_issue do
128
      noteable_id   1
Riyad Preukschas's avatar
Riyad Preukschas committed
129 130
      noteable_type "Issue"
    end
131 132 133
  end

  factory :event do
randx's avatar
randx committed
134 135
    factory :closed_issue_event do
      project
136
      action { Event::CLOSED }
randx's avatar
randx committed
137 138 139
      target factory: :closed_issue
      author factory: :user
    end
140 141 142 143
  end

  factory :key do
    title
Robert Speicher's avatar
Robert Speicher committed
144
    key do
145
      "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0="
Robert Speicher's avatar
Robert Speicher committed
146
    end
147 148 149 150 151 152 153 154

    factory :deploy_key do
      project
    end

    factory :personal_key do
      user
    end
155 156 157 158 159 160

    factory :key_with_a_space_in_the_middle do
      key do
        "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa ++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0="
      end
    end
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
  end

  factory :milestone do
    title
    project
  end

  factory :system_hook do
    url
  end

  factory :project_hook do
    url
  end

  factory :wiki do
    title
    content
    user
  end

  factory :snippet do
    project
    author
    title
    content
187 188 189 190 191 192
    file_name
  end

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

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

  factory :service_hook do
    url
    service
  end
206
end