Commit a7957059 authored by Rémy Coutable's avatar Rémy Coutable

[EE] Replace factory_girl_rails with factory_bot_rails

I've followed the [upgrade guide](https://github.com/thoughtbot/factory_bot/blob/4-9-0-stable/UPGRADE_FROM_FACTORY_GIRL.md) and ran these two commands:

```
grep -e FactoryGirl **/*.rake **/*.rb -s -l | xargs sed -i "" "s|FactoryGirl|FactoryBot|"
grep -e factory_girl **/*.rake **/*.rb -s -l | xargs sed -i "" "s|factory_girl|factory_bot|"
```
Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent 4ea931c2
......@@ -323,7 +323,7 @@ group :development, :test do
gem 'fuubar', '~> 2.2.0'
gem 'database_cleaner', '~> 1.5.0'
gem 'factory_girl_rails', '~> 4.7.0'
gem 'factory_bot_rails', '~> 4.8.2'
gem 'rspec-rails', '~> 3.6.0'
gem 'rspec-retry', '~> 0.4.5'
gem 'spinach-rails', '~> 0.2.1'
......
......@@ -216,10 +216,10 @@ GEM
excon (0.57.1)
execjs (2.6.0)
expression_parser (0.9.0)
factory_girl (4.7.0)
factory_bot (4.8.2)
activesupport (>= 3.0.0)
factory_girl_rails (4.7.0)
factory_girl (~> 4.7.0)
factory_bot_rails (4.8.2)
factory_bot (~> 4.8.2)
railties (>= 3.0.0)
faraday (0.12.2)
multipart-post (>= 1.2, < 3)
......@@ -1051,7 +1051,7 @@ DEPENDENCIES
elasticsearch-rails (~> 0.1.9)
email_reply_trimmer (~> 0.1)
email_spec (~> 1.6.0)
factory_girl_rails (~> 4.7.0)
factory_bot_rails (~> 4.8.2)
faraday (~> 0.12)
faraday_middleware-aws-signers-v4
ffaker (~> 2.4)
......
......@@ -11,7 +11,7 @@ class Projects::NotesController < Projects::ApplicationController
# Controller actions are returned from AbstractController::Base and methods of parent classes are
# excluded in order to return only specific controller related methods.
# That is ok for the app (no :create method in ancestors)
# but fails for tests because there is a :create method on FactoryGirl (one of the ancestors)
# but fails for tests because there is a :create method on FactoryBot (one of the ancestors)
#
# see https://github.com/rails/rails/blob/v4.2.7/actionpack/lib/abstract_controller/base.rb#L78
#
......
......@@ -180,7 +180,7 @@ module Gitlab
config.middleware.insert_after ActionDispatch::Flash, 'Gitlab::Middleware::ReadOnly'
config.generators do |g|
g.factory_girl false
g.factory_bot false
end
config.after_initialize do
......
......@@ -140,8 +140,8 @@ class Gitlab::Seeder::CycleAnalytics
issue.update(milestone: @project.milestones.sample)
else
label_name = "#{FFaker::Product.brand}-#{FFaker::Product.brand}-#{rand(1000)}"
list_label = FactoryGirl.create(:label, title: label_name, project: issue.project)
FactoryGirl.create(:list, board: FactoryGirl.create(:board, project: issue.project), label: list_label)
list_label = FactoryBot.create(:label, title: label_name, project: issue.project)
FactoryBot.create(:list, board: FactoryBot.create(:board, project: issue.project), label: list_label)
issue.update(labels: [list_label])
end
......
......@@ -8,7 +8,7 @@ might encounter or should avoid during development of GitLab CE and EE.
Consider the following factory:
```ruby
FactoryGirl.define do
FactoryBot.define do
factory :label do
sequence(:title) { |n| "label#{n}" }
end
......@@ -53,7 +53,7 @@ When run, this spec doesn't do what we might expect:
(compared using ==)
```
That's because FactoryGirl sequences are not reseted for each example.
That's because FactoryBot sequences are not reseted for each example.
Please remember that sequence-generated values exist only to avoid having to
explicitly set attributes that have a uniqueness constraint when using a factory.
......
......@@ -8,8 +8,8 @@ and effective _as well as_ fast.
Here are some things to keep in mind regarding test performance:
- `double` and `spy` are faster than `FactoryGirl.build(...)`
- `FactoryGirl.build(...)` and `.build_stubbed` are faster than `.create`.
- `double` and `spy` are faster than `FactoryBot.build(...)`
- `FactoryBot.build(...)` and `.build_stubbed` are faster than `.create`.
- Don't `create` an object when `build`, `build_stubbed`, `attributes_for`,
`spy`, or `double` will do. Database persistence is slow!
- Don't mark a feature as requiring JavaScript (through `@javascript` in
......@@ -254,13 +254,13 @@ end
### Factories
GitLab uses [factory_girl] as a test fixture replacement.
GitLab uses [factory_bot] as a test fixture replacement.
- Factory definitions live in `spec/factories/`, named using the pluralization
of their corresponding model (`User` factories are defined in `users.rb`).
- There should be only one top-level factory definition per file.
- FactoryGirl methods are mixed in to all RSpec groups. This means you can (and
should) call `create(...)` instead of `FactoryGirl.create(...)`.
- FactoryBot methods are mixed in to all RSpec groups. This means you can (and
should) call `create(...)` instead of `FactoryBot.create(...)`.
- Make use of [traits] to clean up definitions and usages.
- When defining a factory, don't define attributes that are not required for the
resulting record to pass validation.
......@@ -269,8 +269,8 @@ GitLab uses [factory_girl] as a test fixture replacement.
- Factories don't have to be limited to `ActiveRecord` objects.
[See example](https://gitlab.com/gitlab-org/gitlab-ce/commit/0b8cefd3b2385a21cfed779bd659978c0402766d).
[factory_girl]: https://github.com/thoughtbot/factory_girl
[traits]: http://www.rubydoc.info/gems/factory_girl/file/GETTING_STARTED.md#Traits
[factory_bot]: https://github.com/thoughtbot/factory_bot
[traits]: http://www.rubydoc.info/gems/factory_bot/file/GETTING_STARTED.md#Traits
### Fixtures
......
......@@ -33,7 +33,7 @@ changes should be tested.
## [Testing best practices](best_practices.md)
Everything you should know about how to write good tests: RSpec, FactoryGirl,
Everything you should know about how to write good tests: RSpec, FactoryBot,
system tests, parameterized tests etc.
---
......
......@@ -35,7 +35,7 @@ Spinach.hooks.before_run do
# web editor and merge
TestEnv.disable_pre_receive
include FactoryGirl::Syntax::Methods
include FactoryBot::Syntax::Methods
include GitlabRoutingHelper
end
......
require 'spec_helper'
describe Gitlab::Geo::JwtRequestDecoder do
let!(:primary_node) { FactoryGirl.create(:geo_node, :primary) }
let!(:primary_node) { FactoryBot.create(:geo_node, :primary) }
let(:data) { { input: 123 } }
let(:request) { Gitlab::Geo::TransferRequest.new(data) }
......
......@@ -2,12 +2,12 @@ require 'spec_helper'
describe Gitlab::Geo::OauthSession do
subject { described_class.new }
let(:oauth_app) { FactoryGirl.create(:doorkeeper_application) }
let(:oauth_app) { FactoryBot.create(:doorkeeper_application) }
let(:oauth_return_to) { 'http://localhost:3000/oauth/geo/callback' }
let(:dummy_state) { 'salt:hmac:return_to' }
let(:valid_state) { described_class.new(return_to: oauth_return_to).generate_oauth_state }
let(:access_token) { FactoryGirl.create(:doorkeeper_access_token).token }
let(:user) { FactoryGirl.build(:user) }
let(:access_token) { FactoryBot.create(:doorkeeper_access_token).token }
let(:user) { FactoryBot.build(:user) }
before do
allow(subject).to receive(:oauth_app) { oauth_app }
......
......@@ -63,7 +63,7 @@ describe GeoNode, type: :model do
end
context 'cache expiration' do
let(:new_node) { FactoryGirl.build(:geo_node) }
let(:new_node) { FactoryBot.build(:geo_node) }
it 'expires cache when saved' do
expect(new_node).to receive(:expire_cache!).at_least(:once)
......
FactoryGirl.define do
FactoryBot.define do
factory :abuse_report do
reporter factory: :user
user
......
# Read about factories at https://github.com/thoughtbot/factory_girl
# Read about factories at https://github.com/thoughtbot/factory_bot
FactoryGirl.define do
FactoryBot.define do
factory :appearance do
title "GitLab Enterprise Edition"
description "Open source software to collaborate on code"
......
FactoryGirl.define do
FactoryBot.define do
factory :application_setting do
end
end
# Read about factories at https://github.com/thoughtbot/factory_girl
# Read about factories at https://github.com/thoughtbot/factory_bot
FactoryGirl.define do
FactoryBot.define do
factory :approval do
merge_request
user
......
# Read about factories at https://github.com/thoughtbot/factory_girl
# Read about factories at https://github.com/thoughtbot/factory_bot
FactoryGirl.define do
FactoryBot.define do
factory :approver_group do
target factory: :merge_request
group
......
# Read about factories at https://github.com/thoughtbot/factory_girl
# Read about factories at https://github.com/thoughtbot/factory_bot
FactoryGirl.define do
FactoryBot.define do
factory :approver do
target factory: :merge_request
user
......
FactoryGirl.define do
FactoryBot.define do
factory :audit_event, aliases: [:user_audit_event] do
user
type 'SecurityEvent'
......
FactoryGirl.define do
FactoryBot.define do
factory :award_emoji do
name "thumbsup"
user
......
FactoryGirl.define do
FactoryBot.define do
factory :board_label do
association :board
association :label
......
FactoryGirl.define do
FactoryBot.define do
factory :board do
sequence(:name) { |n| "board#{n}" }
......
FactoryGirl.define do
FactoryBot.define do
factory :broadcast_message do
message "MyText"
starts_at 1.day.ago
......
FactoryGirl.define do
FactoryBot.define do
factory :chat_name, class: ChatName do
user factory: :user
service factory: :service
......
FactoryGirl.define do
FactoryBot.define do
factory :chat_team, class: ChatTeam do
sequence(:team_id) { |n| "abcdefghijklm#{n}" }
namespace factory: :group
......
FactoryGirl.define do
FactoryBot.define do
factory :ci_build_trace_section_name, class: Ci::BuildTraceSectionName do
sequence(:name) { |n| "section_#{n}" }
project factory: :project
......
include ActionDispatch::TestProcess
FactoryGirl.define do
FactoryBot.define do
factory :ci_build, class: Ci::Build do
name 'test'
stage 'test'
......
FactoryGirl.define do
FactoryBot.define do
factory :ci_group_variable, class: Ci::GroupVariable do
sequence(:key) { |n| "VARIABLE_#{n}" }
value 'VARIABLE_VALUE'
......
include ActionDispatch::TestProcess
FactoryGirl.define do
FactoryBot.define do
factory :ci_job_artifact, class: Ci::JobArtifact do
job factory: :ci_build
file_type :archive
......
FactoryGirl.define do
FactoryBot.define do
factory :ci_pipeline_schedule, class: Ci::PipelineSchedule do
cron '0 1 * * *'
cron_timezone Gitlab::Ci::CronParser::VALID_SYNTAX_SAMPLE_TIME_ZONE
......
FactoryGirl.define do
FactoryBot.define do
factory :ci_pipeline_schedule_variable, class: Ci::PipelineScheduleVariable do
sequence(:key) { |n| "VARIABLE_#{n}" }
value 'VARIABLE_VALUE'
......
FactoryGirl.define do
FactoryBot.define do
factory :ci_pipeline_variable, class: Ci::PipelineVariable do
sequence(:key) { |n| "VARIABLE_#{n}" }
value 'VARIABLE_VALUE'
......
FactoryGirl.define do
FactoryBot.define do
factory :ci_empty_pipeline, class: Ci::Pipeline do
source :push
ref 'master'
......
FactoryGirl.define do
FactoryBot.define do
factory :ci_runner_project, class: Ci::RunnerProject do
runner factory: :ci_runner
project
......
FactoryGirl.define do
FactoryBot.define do
factory :ci_runner, class: Ci::Runner do
sequence(:description) { |n| "My runner#{n}" }
......
FactoryGirl.define do
FactoryBot.define do
factory :ci_sources_pipeline, class: Ci::Sources::Pipeline do
after(:build) do |source|
source.project ||= source.pipeline.project
......
FactoryGirl.define do
FactoryBot.define do
factory :ci_stage, class: Ci::LegacyStage do
skip_create
......
FactoryGirl.define do
FactoryBot.define do
factory :ci_trigger_request, class: Ci::TriggerRequest do
trigger factory: :ci_trigger
end
......
FactoryGirl.define do
FactoryBot.define do
factory :ci_trigger_without_token, class: Ci::Trigger do
owner
......
FactoryGirl.define do
FactoryBot.define do
factory :ci_variable, class: Ci::Variable do
sequence(:key) { |n| "VARIABLE_#{n}" }
value 'VARIABLE_VALUE'
......
FactoryGirl.define do
FactoryBot.define do
factory :cluster_applications_helm, class: Clusters::Applications::Helm do
cluster factory: %i(cluster provided_by_gcp)
......
FactoryGirl.define do
FactoryBot.define do
factory :cluster_applications_ingress, class: Clusters::Applications::Ingress do
cluster factory: %i(cluster provided_by_gcp)
......
FactoryGirl.define do
FactoryBot.define do
factory :cluster, class: Clusters::Cluster do
user
name 'test-cluster'
......
FactoryGirl.define do
FactoryBot.define do
factory :cluster_platform_kubernetes, class: Clusters::Platforms::Kubernetes do
cluster
namespace nil
......
FactoryGirl.define do
FactoryBot.define do
factory :cluster_provider_gcp, class: Clusters::Providers::Gcp do
cluster
gcp_project_id 'test-gcp-project'
......
FactoryGirl.define do
FactoryBot.define do
factory :commit_status, class: CommitStatus do
name 'default'
stage 'test'
......
require_relative '../support/repo_helpers'
FactoryGirl.define do
FactoryBot.define do
factory :commit do
git_commit RepoHelpers.sample_commit
project
......
FactoryGirl.define do
FactoryBot.define do
factory :container_repository do
name 'test_container_image'
project
......
FactoryGirl.define do
FactoryBot.define do
factory :conversational_development_index_metric, class: ConversationalDevelopmentIndex::Metric do
leader_issues 9.256
instance_issues 1.234
......
FactoryGirl.define do
FactoryBot.define do
factory :deploy_keys_project do
deploy_key
project
......
FactoryGirl.define do
FactoryBot.define do
factory :deployment, class: Deployment do
sha '97de212e80737a608d939f648d959671fb0a0142'
ref 'master'
......
FactoryGirl.define do
FactoryBot.define do
factory :doorkeeper_access_grant, class: Doorkeeper::AccessGrant do
sequence(:resource_owner_id) { |n| n }
association :application, factory: :doorkeeper_application
......
FactoryGirl.define do
FactoryBot.define do
factory :email do
user
email { generate(:email_alias) }
......
FactoryGirl.define do
FactoryBot.define do
factory :environment, class: Environment do
sequence(:name) { |n| "environment#{n}" }
......
FactoryGirl.define do
FactoryBot.define do
factory :epic_issue do
epic
issue
......
FactoryGirl.define do
FactoryBot.define do
factory :epic do
title { generate(:title) }
group
......
FactoryGirl.define do
FactoryBot.define do
factory :event do
project
author factory: :user
......
FactoryGirl.define do
FactoryBot.define do
factory :file_uploader do
skip_create
......
FactoryGirl.define do
FactoryBot.define do
factory :fork_network_member do
association :project
association :fork_network
......
FactoryGirl.define do
FactoryBot.define do
factory :fork_network do
association :root_project, factory: :project
end
......
FactoryGirl.define do
FactoryBot.define do
factory :forked_project_link do
association :forked_to_project, factory: [:project, :repository]
association :forked_from_project, factory: [:project, :repository]
......
FactoryGirl.define do
FactoryBot.define do
factory :geo_event_log, class: Geo::EventLog do
trait :created_event do
repository_created_event factory: :geo_repository_created_event
......
FactoryGirl.define do
FactoryBot.define do
factory :geo_event_log_state, class: Geo::EventLogState do
sequence(:event_id)
end
......
FactoryGirl.define do
FactoryBot.define do
factory :geo_file_registry, class: Geo::FileRegistry do
sequence(:file_id)
file_type :file
......
FactoryGirl.define do
FactoryBot.define do
factory :geo_project_registry, class: Geo::ProjectRegistry do
project
last_repository_synced_at nil
......
FactoryGirl.define do
FactoryBot.define do
factory :geo_node_namespace_link do
geo_node
namespace
......
FactoryGirl.define do
FactoryBot.define do
factory :geo_node_status do
sequence(:id)
geo_node
......
FactoryGirl.define do
FactoryBot.define do
factory :geo_node do
# Start at a number higher than the current port to avoid the GeoNode
# "lock out" validation
......
FactoryGirl.define do
FactoryBot.define do
sequence(:gitaly_commit_id) { Digest::SHA1.hexdigest(Time.now.to_f.to_s) }
factory :gitaly_commit, class: Gitaly::GitCommit do
......
FactoryGirl.define do
FactoryBot.define do
factory :gitaly_commit_author, class: Gitaly::CommitAuthor do
skip_create
......
require_relative '../support/gpg_helpers'
FactoryGirl.define do
FactoryBot.define do
factory :gpg_key_subkey do
gpg_key
......
require_relative '../support/gpg_helpers'
FactoryGirl.define do
FactoryBot.define do
factory :gpg_key do
key GpgHelpers::User1.public_key
user
......
require_relative '../support/gpg_helpers'
FactoryGirl.define do
FactoryBot.define do
factory :gpg_signature do
commit_sha { Digest::SHA1.hexdigest(SecureRandom.hex) }
project
......
FactoryGirl.define do
FactoryBot.define do
factory :group_custom_attribute do
group
sequence(:key) { |n| "key#{n}" }
......
FactoryGirl.define do
FactoryBot.define do
factory :group_hook do
url { generate(:url) }
end
......
FactoryGirl.define do
FactoryBot.define do
factory :group_member do
access_level { GroupMember::OWNER }
group
......
FactoryGirl.define do
FactoryBot.define do
factory :group, class: Group, parent: :namespace do
sequence(:name) { |n| "group#{n}" }
path { name.downcase.gsub(/\s/, '_') }
......
FactoryGirl.define do
FactoryBot.define do
factory :identity do
provider 'ldapmain'
extern_uid 'my-ldap-id'
......
FactoryGirl.define do
FactoryBot.define do
factory :instance_configuration do
skip_create
end
......
FactoryGirl.define do
FactoryBot.define do
factory :issue_link do
source factory: :issue
target factory: :issue
......
FactoryGirl.define do
FactoryBot.define do
factory :issue do
title { generate(:title) }
author
......
require_relative '../support/helpers/key_generator_helper'
FactoryGirl.define do
FactoryBot.define do
factory :key do
title
key { Spec::Support::Helpers::KeyGeneratorHelper.new(1024).generate + ' dummy@gitlab.com' }
......
FactoryGirl.define do
FactoryBot.define do
factory :label_link do
label
target factory: :issue
......
FactoryGirl.define do
FactoryBot.define do
factory :label_priority do
project
label
......
FactoryGirl.define do
FactoryBot.define do
trait :base_label do
title { generate(:label_title) }
color "#990000"
......
FactoryGirl.define do
FactoryBot.define do
factory :ldap_group_link do
cn 'group1'
group_access Gitlab::Access::GUEST
......
include ActionDispatch::TestProcess
FactoryGirl.define do
FactoryBot.define do
factory :lfs_object do
sequence(:oid) { |n| "b68143e6463773b1b6c6fd009a76c32aeec041faff32ba2ed42fd7f708a%05x" % n }
size 499013
......
FactoryGirl.define do
FactoryBot.define do
factory :lfs_objects_project do
lfs_object
project
......
FactoryGirl.define do
FactoryBot.define do
factory :gitlab_license, class: "Gitlab::License" do
skip_create
......
FactoryGirl.define do
FactoryBot.define do
factory :list do
board
label
......
FactoryGirl.define do
FactoryBot.define do
factory :merge_request do
title { generate(:title) }
author
......
FactoryGirl.define do
FactoryBot.define do
factory :merge_requests_closing_issues do
issue
merge_request
......
FactoryGirl.define do
FactoryBot.define do
factory :milestone do
title
......
FactoryGirl.define do
FactoryBot.define do
factory :namespace_statistics do
namespace factory: :namespace
end
......
FactoryGirl.define do
FactoryBot.define do
factory :namespace do
sequence(:name) { |n| "namespace#{n}" }
path { name.downcase.gsub(/\s/, '_') }
......
......@@ -2,7 +2,7 @@ require_relative '../support/repo_helpers'
include ActionDispatch::TestProcess
FactoryGirl.define do
FactoryBot.define do
factory :note do
project
note { generate(:title) }
......
FactoryGirl.define do
FactoryBot.define do
factory :notification_setting do
source factory: :project
user
......
FactoryGirl.define do
FactoryBot.define do
factory :oauth_access_grant do
resource_owner_id { create(:user).id }
application
......
FactoryGirl.define do
FactoryBot.define do
factory :oauth_access_token do
resource_owner
application
......
FactoryGirl.define do
FactoryBot.define do
factory :oauth_application, class: 'Doorkeeper::Application', aliases: [:application] do
sequence(:name) { |n| "OAuth App #{n}" }
uid { Doorkeeper::OAuth::Helpers::UniqueToken.generate }
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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