factories.rb 3.85 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 12 13
  sequence(:url) { Faker::Internet.uri('http') }

  factory :user, aliases: [:author, :assignee, :owner] do
    email { Faker::Internet.email }
14
    name
15
    username { Faker::Internet.user_name }
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 30 31
    owner
  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 40 41 42
  factory :namespace do
    sequence(:name) { |n| "group#{n}" }
    path { name.downcase.gsub(/\s/, '_') }
    owner
43 44
  end

45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
  factory :users_project do
    user
    project
  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"
68 69 70 71 72

    trait :closed do
      closed true
    end

73 74 75 76 77 78 79 80 81 82 83 84 85 86
    # pick 3 commits "at random" (from bcf03b5d~3 to bcf03b5d)
    trait :with_diffs do
      target_branch "bcf03b5d~3"
      source_branch "bcf03b5d"
      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

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

  factory :note do
    project
    note "Note"
Riyad Preukschas's avatar
Riyad Preukschas committed
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
    author

    factory :note_on_commit, traits: [:on_commit]
    factory :note_on_commit_line, traits: [:on_commit, :on_line]
    factory :note_on_issue, traits: [:on_issue], aliases: [:votable_note]
    factory :note_on_merge_request, traits: [:on_merge_request]
    factory :note_on_merge_request_line, traits: [:on_merge_request, :on_line]

    trait :on_commit do
      noteable_id   "bcf03b5de6c33f3869ef70d68cf06e679d1d7f9a"
      noteable_type "Commit"
    end

    trait :on_line do
      line_code "0_184_184"
    end

    trait :on_merge_request do
      noteable_id   1
      noteable_type "MergeRequest"
    end

    trait :on_issue do
      noteable_id 1
      noteable_type "Issue"
    end
120 121 122
  end

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

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

    factory :deploy_key do
      project
    end

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

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

  factory :protected_branch do
    name
    project
182
  end
183 184 185 186 187 188 189 190 191 192 193 194

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

  factory :service_hook do
    url
    service
  end
195
end