Skip to content
Snippets Groups Projects
Commit 627a9687 authored by Robert Speicher's avatar Robert Speicher
Browse files

Merge branch 'rc/use-factory_bot_rails' into 'master'

Replace factory_girl_rails with factory_bot_rails

See merge request gitlab-org/gitlab-ce!15919
parents d2f313dc 4af9d592
No related branches found
No related tags found
No related merge requests found
Showing
with 32 additions and 32 deletions
Loading
Loading
@@ -311,7 +311,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'
Loading
Loading
Loading
Loading
@@ -195,10 +195,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)
Loading
Loading
@@ -1020,7 +1020,7 @@ DEPENDENCIES
dropzonejs-rails (~> 0.7.1)
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)
ffaker (~> 2.4)
flay (~> 2.8.0)
Loading
Loading
Loading
Loading
@@ -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
#
Loading
Loading
Loading
Loading
@@ -163,7 +163,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
Loading
Loading
Loading
Loading
@@ -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
 
Loading
Loading
Loading
Loading
@@ -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
Loading
Loading
@@ -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.
Loading
Loading
Loading
Loading
@@ -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
Loading
Loading
@@ -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.
Loading
Loading
@@ -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
 
Loading
Loading
Loading
Loading
@@ -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.
 
---
Loading
Loading
Loading
Loading
@@ -27,7 +27,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
 
Loading
Loading
FactoryGirl.define do
FactoryBot.define do
factory :abuse_report do
reporter factory: :user
user
Loading
Loading
# 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 "MepMep"
description "This is my Community Edition instance"
Loading
Loading
FactoryGirl.define do
FactoryBot.define do
factory :application_setting do
end
end
FactoryGirl.define do
FactoryBot.define do
factory :award_emoji do
name "thumbsup"
user
Loading
Loading
FactoryGirl.define do
FactoryBot.define do
factory :board do
project
 
Loading
Loading
FactoryGirl.define do
FactoryBot.define do
factory :broadcast_message do
message "MyText"
starts_at 1.day.ago
Loading
Loading
FactoryGirl.define do
FactoryBot.define do
factory :chat_name, class: ChatName do
user factory: :user
service factory: :service
Loading
Loading
FactoryGirl.define do
FactoryBot.define do
factory :chat_team, class: ChatTeam do
sequence(:team_id) { |n| "abcdefghijklm#{n}" }
namespace factory: :group
Loading
Loading
FactoryGirl.define do
FactoryBot.define do
factory :ci_build_trace_section_name, class: Ci::BuildTraceSectionName do
sequence(:name) { |n| "section_#{n}" }
project factory: :project
Loading
Loading
include ActionDispatch::TestProcess
 
FactoryGirl.define do
FactoryBot.define do
factory :ci_build, class: Ci::Build do
name 'test'
stage 'test'
Loading
Loading
FactoryGirl.define do
FactoryBot.define do
factory :ci_group_variable, class: Ci::GroupVariable do
sequence(:key) { |n| "VARIABLE_#{n}" }
value 'VARIABLE_VALUE'
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment