factories.rb 4.07 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 72 73

    trait :closed do
      closed true
    end

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

88
    factory :closed_merge_request, traits: [:closed]
89
    factory :merge_request_with_diffs, traits: [:with_diffs]
90 91 92 93 94
  end

  factory :note do
    project
    note "Note"
Riyad Preukschas's avatar
Riyad Preukschas committed
95 96 97
    author

    factory :note_on_commit, traits: [:on_commit]
Riyad Preukschas's avatar
Riyad Preukschas committed
98
    factory :note_on_commit_diff, traits: [:on_commit, :on_diff]
Riyad Preukschas's avatar
Riyad Preukschas committed
99 100
    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
101
    factory :note_on_merge_request_diff, traits: [:on_merge_request, :on_diff]
Riyad Preukschas's avatar
Riyad Preukschas committed
102 103

    trait :on_commit do
104
      commit_id     "bcf03b5de6c33f3869ef70d68cf06e679d1d7f9a"
Riyad Preukschas's avatar
Riyad Preukschas committed
105 106 107
      noteable_type "Commit"
    end

Riyad Preukschas's avatar
Riyad Preukschas committed
108
    trait :on_diff do
Riyad Preukschas's avatar
Riyad Preukschas committed
109 110 111 112 113 114 115 116 117
      line_code "0_184_184"
    end

    trait :on_merge_request do
      noteable_id   1
      noteable_type "MergeRequest"
    end

    trait :on_issue do
118
      noteable_id   1
Riyad Preukschas's avatar
Riyad Preukschas committed
119 120
      noteable_type "Issue"
    end
121 122 123
  end

  factory :event do
randx's avatar
randx committed
124 125
    factory :closed_issue_event do
      project
126
      action { Event::CLOSED }
randx's avatar
randx committed
127 128 129
      target factory: :closed_issue
      author factory: :user
    end
130 131 132 133
  end

  factory :key do
    title
Robert Speicher's avatar
Robert Speicher committed
134
    key do
135
      "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0="
Robert Speicher's avatar
Robert Speicher committed
136
    end
137 138 139 140 141 142 143 144

    factory :deploy_key do
      project
    end

    factory :personal_key do
      user
    end
145 146 147 148 149 150

    factory :key_with_a_space_in_the_middle do
      key do
        "ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa ++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0="
      end
    end
151 152 153 154 155 156

    factory :invalid_key do
      key do
        "ssh-rsa this_is_invalid_key=="
      end
    end
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 182
  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
183 184 185 186 187 188
    file_name
  end

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

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

  factory :service_hook do
    url
    service
  end
202
end