Commit 92d89618 authored by Douwe Maan's avatar Douwe Maan

Merge branch 'rs-organize-factories' into 'master'

Factory cleanup

Related: https://gitlab.com/gitlab-org/gitlab-ce/issues/5880

See merge request !2847
parents e7c4c22c fcfdb23a
...@@ -261,7 +261,7 @@ group :development, :test do ...@@ -261,7 +261,7 @@ group :development, :test do
gem 'fuubar', '~> 2.0.0' gem 'fuubar', '~> 2.0.0'
gem 'database_cleaner', '~> 1.4.0' gem 'database_cleaner', '~> 1.4.0'
gem 'factory_girl_rails', '~> 4.3.0' gem 'factory_girl_rails', '~> 4.6.0'
gem 'rspec-rails', '~> 3.3.0' gem 'rspec-rails', '~> 3.3.0'
gem 'spinach-rails', '~> 0.2.1' gem 'spinach-rails', '~> 0.2.1'
......
...@@ -194,10 +194,10 @@ GEM ...@@ -194,10 +194,10 @@ GEM
excon (0.45.4) excon (0.45.4)
execjs (2.6.0) execjs (2.6.0)
expression_parser (0.9.0) expression_parser (0.9.0)
factory_girl (4.3.0) factory_girl (4.5.0)
activesupport (>= 3.0.0) activesupport (>= 3.0.0)
factory_girl_rails (4.3.0) factory_girl_rails (4.6.0)
factory_girl (~> 4.3.0) factory_girl (~> 4.5.0)
railties (>= 3.0.0) railties (>= 3.0.0)
faraday (0.9.2) faraday (0.9.2)
multipart-post (>= 1.2, < 3) multipart-post (>= 1.2, < 3)
...@@ -916,7 +916,7 @@ DEPENDENCIES ...@@ -916,7 +916,7 @@ DEPENDENCIES
dropzonejs-rails (~> 0.7.1) dropzonejs-rails (~> 0.7.1)
email_reply_parser (~> 0.5.8) email_reply_parser (~> 0.5.8)
email_spec (~> 1.6.0) email_spec (~> 1.6.0)
factory_girl_rails (~> 4.3.0) factory_girl_rails (~> 4.6.0)
ffaker (~> 2.0.0) ffaker (~> 2.0.0)
flay flay
flog flog
......
...@@ -93,5 +93,9 @@ module Gitlab ...@@ -93,5 +93,9 @@ module Gitlab
# This is needed for gitlab-shell # This is needed for gitlab-shell
ENV['GITLAB_PATH_OUTSIDE_HOOK'] = ENV['PATH'] ENV['GITLAB_PATH_OUTSIDE_HOOK'] = ENV['PATH']
config.generators do |g|
g.factory_girl false
end
end end
end end
include ActionDispatch::TestProcess
FactoryGirl.define do
sequence :sentence, aliases: [:title, :content] do
FFaker::Lorem.sentence
end
sequence :name do
FFaker::Name.name
end
sequence :file_name do
FFaker::Internet.user_name
end
sequence(:url) { FFaker::Internet.uri('http') }
factory :user, aliases: [:author, :assignee, :owner, :creator] do
email { FFaker::Internet.email }
name
sequence(:username) { |n| "#{FFaker::Internet.user_name}#{n}" }
password "12345678"
confirmed_at { Time.now }
confirmation_token { nil }
can_create_group true
trait :admin do
admin true
end
trait :two_factor do
before(:create) do |user|
user.two_factor_enabled = true
user.otp_secret = User.generate_otp_secret(32)
user.otp_grace_period_started_at = Time.now
user.generate_otp_backup_codes!
end
end
trait :with_avatar do
avatar { fixture_file_upload(Rails.root.join(*%w(spec fixtures dk.png)), 'image/png') }
avatar_crop_x 0
avatar_crop_y 0
avatar_crop_size 256
end
factory :omniauth_user do
ignore do
extern_uid '123456'
provider 'ldapmain'
end
after(:create) do |user, evaluator|
user.identities << create(
:identity,
provider: evaluator.provider,
extern_uid: evaluator.extern_uid
)
end
end
factory :admin, traits: [:admin]
end
factory :group do
sequence(:name) { |n| "group#{n}" }
path { name.downcase.gsub(/\s/, '_') }
type 'Group'
end
factory :namespace do
sequence(:name) { |n| "namespace#{n}" }
path { name.downcase.gsub(/\s/, '_') }
owner
end
factory :project_member do
user
project
access_level { ProjectMember::MASTER }
end
factory :issue do
title
author
project
trait :closed do
state :closed
end
trait :reopened do
state :reopened
end
factory :closed_issue, traits: [:closed]
factory :reopened_issue, traits: [:reopened]
end
factory :event do
factory :closed_issue_event do
project
action { Event::CLOSED }
target factory: :closed_issue
author factory: :user
end
end
factory :key do
title
key do
"ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0= dummy@gitlab.com"
end
factory :deploy_key, class: 'DeployKey' do
end
factory :personal_key do
user
end
factory :another_key do
key do
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDmTillFzNTrrGgwaCKaSj+QCz81E6jBc/s9av0+3b1Hwfxgkqjl4nAK/OD2NjgyrONDTDfR8cRN4eAAy6nY8GLkOyYBDyuc5nTMqs5z3yVuTwf3koGm/YQQCmo91psZ2BgDFTor8SVEE5Mm1D1k3JDMhDFxzzrOtRYFPci9lskTJaBjpqWZ4E9rDTD2q/QZntCqbC3wE9uSemRQB5f8kik7vD/AD8VQXuzKladrZKkzkONCPWsXDspUitjM8HkQdOf0PsYn1CMUC1xKYbCxkg5TkEosIwGv6CoEArUrdu/4+10LVslq494mAvEItywzrluCLCnwELfW+h/m8UHoVhZ"
end
factory :another_deploy_key, class: 'DeployKey' do
end
end
end
factory :email do
user
email do
FFaker::Internet.email('alias')
end
factory :another_email do
email do
FFaker::Internet.email('another.alias')
end
end
end
factory :milestone do
title
project
trait :closed do
state :closed
end
factory :closed_milestone, traits: [:closed]
end
factory :system_hook do
url
end
factory :project_hook do
url
end
factory :project_snippet do
project
author
title
content
file_name
end
factory :personal_snippet do
author
title
content
file_name
trait :public do
visibility_level Gitlab::VisibilityLevel::PUBLIC
end
trait :internal do
visibility_level Gitlab::VisibilityLevel::INTERNAL
end
trait :private do
visibility_level Gitlab::VisibilityLevel::PRIVATE
end
end
factory :snippet do
author
title
content
file_name
end
factory :protected_branch do
name
project
end
factory :service do
type ""
title "GitLab CI"
project
end
factory :service_hook do
url
service
end
factory :deploy_keys_project do
deploy_key
project
end
factory :identity do
provider 'ldapmain'
extern_uid 'my-ldap-id'
end
factory :sent_notification do
project
recipient factory: :user
noteable factory: :issue
reply_key "0123456789abcdef" * 2
end
end
...@@ -10,8 +10,6 @@ ...@@ -10,8 +10,6 @@
# updated_at :datetime # updated_at :datetime
# #
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do FactoryGirl.define do
factory :abuse_report do factory :abuse_report do
reporter factory: :user reporter factory: :user
......
...@@ -12,8 +12,6 @@ ...@@ -12,8 +12,6 @@
# font :string(255) # font :string(255)
# #
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do FactoryGirl.define do
factory :broadcast_message do factory :broadcast_message do
message "MyText" message "MyText"
......
include ActionDispatch::TestProcess
FactoryGirl.define do FactoryGirl.define do
factory :ci_build, class: Ci::Build do factory :ci_build, class: Ci::Build do
name 'test' name 'test'
......
...@@ -16,7 +16,6 @@ ...@@ -16,7 +16,6 @@
# gl_project_id :integer # gl_project_id :integer
# #
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do FactoryGirl.define do
factory :ci_empty_commit, class: Ci::Commit do factory :ci_empty_commit, class: Ci::Commit do
sha '97de212e80737a608d939f648d959671fb0a0142' sha '97de212e80737a608d939f648d959671fb0a0142'
......
...@@ -9,8 +9,6 @@ ...@@ -9,8 +9,6 @@
# updated_at :datetime # updated_at :datetime
# #
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do FactoryGirl.define do
factory :ci_runner_project, class: Ci::RunnerProject do factory :ci_runner_project, class: Ci::RunnerProject do
runner_id 1 runner_id 1
......
...@@ -17,8 +17,6 @@ ...@@ -17,8 +17,6 @@
# architecture :string(255) # architecture :string(255)
# #
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do FactoryGirl.define do
factory :ci_runner, class: Ci::Runner do factory :ci_runner, class: Ci::Runner do
sequence :description do |n| sequence :description do |n|
......
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do FactoryGirl.define do
factory :ci_trigger_request, class: Ci::TriggerRequest do factory :ci_trigger_request, class: Ci::TriggerRequest do
factory :ci_trigger_request_with_variables do factory :ci_trigger_request_with_variables do
......
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do FactoryGirl.define do
factory :ci_trigger_without_token, class: Ci::Trigger do factory :ci_trigger_without_token, class: Ci::Trigger do
factory :ci_trigger do factory :ci_trigger do
......
...@@ -12,8 +12,6 @@ ...@@ -12,8 +12,6 @@
# gl_project_id :integer # gl_project_id :integer
# #
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do FactoryGirl.define do
factory :ci_variable, class: Ci::Variable do factory :ci_variable, class: Ci::Variable do
sequence(:key) { |n| "VARIABLE_#{n}" } sequence(:key) { |n| "VARIABLE_#{n}" }
......
FactoryGirl.define do
factory :deploy_keys_project do
deploy_key
project
end
end
FactoryGirl.define do
factory :email do
user
email do
FFaker::Internet.email('alias')
end
factory :another_email do
email do
FFaker::Internet.email('another.alias')
end
end
end
end
FactoryGirl.define do
factory :event do
factory :closed_issue_event do
project
action { Event::CLOSED }
target factory: :closed_issue
author factory: :user
end
end
end
...@@ -9,8 +9,6 @@ ...@@ -9,8 +9,6 @@
# updated_at :datetime # updated_at :datetime
# #
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do FactoryGirl.define do
factory :forked_project_link do factory :forked_project_link do
association :forked_to_project, factory: :project association :forked_to_project, factory: :project
......
FactoryGirl.define do
factory :group do
sequence(:name) { |n| "group#{n}" }
path { name.downcase.gsub(/\s/, '_') }
type 'Group'
end
end
FactoryGirl.define do
factory :identity do
provider 'ldapmain'
extern_uid 'my-ldap-id'
end
end
FactoryGirl.define do
factory :issue do
title
author
project
trait :closed do
state :closed
end
trait :reopened do
state :reopened
end
factory :closed_issue, traits: [:closed]
factory :reopened_issue, traits: [:reopened]
end
end
FactoryGirl.define do
factory :key do
title
key do
"ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAiPWx6WM4lhHNedGfBpPJNPpZ7yKu+dnn1SJejgt4596k6YjzGGphH2TUxwKzxcKDKKezwkpfnxPkSMkuEspGRt/aZZ9wa++Oi7Qkr8prgHc4soW6NUlfDzpvZK2H5E7eQaSeP3SAwGmQKUFHCddNaP0L+hM7zhFNzjFvpaMgJw0= dummy@gitlab.com"
end
factory :deploy_key, class: 'DeployKey' do
end
factory :personal_key do
user
end
factory :another_key do
key do
"ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDmTillFzNTrrGgwaCKaSj+QCz81E6jBc/s9av0+3b1Hwfxgkqjl4nAK/OD2NjgyrONDTDfR8cRN4eAAy6nY8GLkOyYBDyuc5nTMqs5z3yVuTwf3koGm/YQQCmo91psZ2BgDFTor8SVEE5Mm1D1k3JDMhDFxzzrOtRYFPci9lskTJaBjpqWZ4E9rDTD2q/QZntCqbC3wE9uSemRQB5f8kik7vD/AD8VQXuzKladrZKkzkONCPWsXDspUitjM8HkQdOf0PsYn1CMUC1xKYbCxkg5TkEosIwGv6CoEArUrdu/4+10LVslq494mAvEItywzrluCLCnwELfW+h/m8UHoVhZ"
end
factory :another_deploy_key, class: 'DeployKey' do
end
end
end
end
...@@ -10,8 +10,6 @@ ...@@ -10,8 +10,6 @@
# updated_at :datetime # updated_at :datetime
# #
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do FactoryGirl.define do
factory :label_link do factory :label_link do
label label
......
...@@ -11,8 +11,6 @@ ...@@ -11,8 +11,6 @@
# template :boolean default(FALSE) # template :boolean default(FALSE)
# #
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do FactoryGirl.define do
factory :label do factory :label do
title "Bug" title "Bug"
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
# file :string(255) # file :string(255)
# #
# Read about factories at https://github.com/thoughtbot/factory_girl include ActionDispatch::TestProcess
FactoryGirl.define do FactoryGirl.define do
factory :lfs_object do factory :lfs_object do
......
...@@ -9,8 +9,6 @@ ...@@ -9,8 +9,6 @@
# updated_at :datetime # updated_at :datetime
# #
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do FactoryGirl.define do
factory :lfs_objects_project do factory :lfs_objects_project do
lfs_object lfs_object
......
FactoryGirl.define do
factory :milestone do
title
project
trait :closed do
state :closed
end
factory :closed_milestone, traits: [:closed]
end
end
FactoryGirl.define do
factory :namespace do
sequence(:name) { |n| "namespace#{n}" }
path { name.downcase.gsub(/\s/, '_') }
owner
end
end
...@@ -21,6 +21,8 @@ ...@@ -21,6 +21,8 @@
require_relative '../support/repo_helpers' require_relative '../support/repo_helpers'
include ActionDispatch::TestProcess
FactoryGirl.define do FactoryGirl.define do
factory :note do factory :note do
project project
......
FactoryGirl.define do
factory :personal_snippet, parent: :snippet, class: :PersonalSnippet do
trait :public do
visibility_level PersonalSnippet::PUBLIC
end
trait :internal do
visibility_level PersonalSnippet::INTERNAL
end
trait :private do
visibility_level PersonalSnippet::PRIVATE
end
end
end
FactoryGirl.define do
factory :project_hook do
url { FFaker::Internet.uri('http') }
end
end
FactoryGirl.define do
factory :project_member do
user
project
access_level { ProjectMember::MASTER }
end
end
FactoryGirl.define do
factory :project_snippet do
project
author
title
content
file_name
end
end
FactoryGirl.define do
factory :protected_branch do
name
project
end
end
...@@ -10,8 +10,6 @@ ...@@ -10,8 +10,6 @@
# updated_at :datetime # updated_at :datetime
# #
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do FactoryGirl.define do
factory :release do factory :release do
tag "v1.1.0" tag "v1.1.0"
......
FactoryGirl.define do
factory :sent_notification do
project
recipient factory: :user
noteable factory: :issue
reply_key "0123456789abcdef" * 2
end
end
FactoryGirl.define do
factory :service_hook do
url { FFaker::Internet.uri('http') }
service
end
end
FactoryGirl.define do
factory :service do
type ""
title "GitLab CI"
project
end
end
FactoryGirl.define do
sequence :title, aliases: [:content] do
FFaker::Lorem.sentence
end
sequence :file_name do
FFaker::Internet.user_name
end
factory :snippet do
author
title
content
file_name
end
end
# Read about factories at https://github.com/thoughtbot/factory_girl
FactoryGirl.define do FactoryGirl.define do
factory :spam_log do factory :spam_log do
user user
......
FactoryGirl.define do
factory :system_hook do
url { FFaker::Internet.uri('http') }
end
end
FactoryGirl.define do
sequence(:name) { FFaker::Name.name }
factory :user, aliases: [:author, :assignee, :recipient, :owner, :creator] do
email { FFaker::Internet.email }
name
sequence(:username) { |n| "#{FFaker::Internet.user_name}#{n}" }
password "12345678"
confirmed_at { Time.now }
confirmation_token { nil }
can_create_group true
trait :admin do
admin true
end
trait :two_factor do
before(:create) do |user|
user.two_factor_enabled = true
user.otp_secret = User.generate_otp_secret(32)
user.otp_grace_period_started_at = Time.now
user.generate_otp_backup_codes!
end
end
trait :with_avatar do
avatar { fixture_file_upload(Rails.root.join(*%w(spec fixtures dk.png)), 'image/png') }
avatar_crop_x 0
avatar_crop_y 0
avatar_crop_size 256
end
factory :omniauth_user do
transient do
extern_uid '123456'
provider 'ldapmain'
end
after(:create) do |user, evaluator|
user.identities << create(
:identity,
provider: evaluator.provider,
extern_uid: evaluator.extern_uid
)
end
end
factory :admin, traits: [:admin]
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment