factories.rb 4.09 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 57 58 59 60 61 62 63 64 65 66 67 68
  end

  factory :issue do
    title
    author
    project

    trait :closed do
      closed true
    end

    factory :closed_issue, traits: [:closed]
  end

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

70 71
    # pick 3 commits "at random" (from bcf03b5d~3 to bcf03b5d)
    trait :with_diffs do
Riyad Preukschas's avatar
Riyad Preukschas committed
72 73
      target_branch "master" # pretend bcf03b5d~3
      source_branch "stable" # pretend bcf03b5d
74 75 76 77 78 79 80 81 82 83
      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

84 85 86 87 88 89 90 91
    trait :closed do
      state :closed
    end

    trait :reopened do
      state :reopened
    end

92
    factory :closed_merge_request, traits: [:closed]
93
    factory :reopened_merge_request, traits: [:reopened]
94
    factory :merge_request_with_diffs, traits: [:with_diffs]
95 96 97 98 99
  end

  factory :note do
    project
    note "Note"
Riyad Preukschas's avatar
Riyad Preukschas committed
100 101 102
    author

    factory :note_on_commit, traits: [:on_commit]
Riyad Preukschas's avatar
Riyad Preukschas committed
103
    factory :note_on_commit_diff, traits: [:on_commit, :on_diff]
Riyad Preukschas's avatar
Riyad Preukschas committed
104 105
    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
106
    factory :note_on_merge_request_diff, traits: [:on_merge_request, :on_diff]
Riyad Preukschas's avatar
Riyad Preukschas committed
107 108

    trait :on_commit do
109
      commit_id     "bcf03b5de6c33f3869ef70d68cf06e679d1d7f9a"
Riyad Preukschas's avatar
Riyad Preukschas committed
110 111 112
      noteable_type "Commit"
    end

Riyad Preukschas's avatar
Riyad Preukschas committed
113
    trait :on_diff do
Riyad Preukschas's avatar
Riyad Preukschas committed
114 115 116 117 118 119 120 121 122
      line_code "0_184_184"
    end

    trait :on_merge_request do
      noteable_id   1
      noteable_type "MergeRequest"
    end

    trait :on_issue do
123
      noteable_id   1
Riyad Preukschas's avatar
Riyad Preukschas committed
124 125
      noteable_type "Issue"
    end
126 127 128
  end

  factory :event do
randx's avatar
randx committed
129 130
    factory :closed_issue_event do
      project
131
      action { Event::CLOSED }
randx's avatar
randx committed
132 133 134
      target factory: :closed_issue
      author factory: :user
    end
135 136 137 138
  end

  factory :key do
    title
Robert Speicher's avatar
Robert Speicher committed
139
    key do
140
      "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0="
Robert Speicher's avatar
Robert Speicher committed
141
    end
142 143 144 145 146 147 148 149

    factory :deploy_key do
      project
    end

    factory :personal_key do
      user
    end
150 151 152 153 154 155

    factory :key_with_a_space_in_the_middle do
      key do
        "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa ++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0="
      end
    end
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
  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
182 183 184 185 186 187
    file_name
  end

  factory :protected_branch do
    name
    project
188
  end
189 190 191 192 193 194 195 196 197 198 199 200

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

  factory :service_hook do
    url
    service
  end
201
end