Skip to content

Commit

Permalink
Merge pull request #4092 from DavidKang/factory_bot
Browse files Browse the repository at this point in the history
Replace FactoryGirlRails with FactoryBotRails
  • Loading branch information
bgeuken committed Dec 7, 2017
2 parents d83aada + 47801e7 commit 1d23619
Show file tree
Hide file tree
Showing 51 changed files with 61 additions and 61 deletions.
2 changes: 1 addition & 1 deletion src/api/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ group :development, :test do
# as testing framework
gem 'rspec-rails', '~> 3.5.0'
# for fixtures
gem 'factory_girl_rails'
gem 'factory_bot_rails'
# for mocking the backend
gem 'vcr'
# as alternative to the standard IRB shell
Expand Down
8 changes: 4 additions & 4 deletions src/api/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -119,10 +119,10 @@ GEM
erubi (1.7.0)
escape_utils (1.2.1)
execjs (2.7.0)
factory_girl (4.8.0)
factory_bot (4.8.2)
activesupport (>= 3.0.0)
factory_girl_rails (4.8.0)
factory_girl (~> 4.8.0)
factory_bot_rails (4.8.2)
factory_bot (~> 4.8.2)
railties (>= 3.0.0)
faker (1.8.4)
i18n (~> 0.5)
Expand Down Expand Up @@ -446,7 +446,7 @@ DEPENDENCIES
database_cleaner (>= 1.0.1)
delayed_job_active_record (>= 4.0.0)
escape_utils
factory_girl_rails
factory_bot_rails
faker
feature
flog (> 4.1.0)
Expand Down
4 changes: 2 additions & 2 deletions src/api/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ class Application < Rails::Application
# we're not threadsafe
config.allow_concurrency = false

# we don't want factory_girl to interfer with the legacy test suite
# we don't want factory_bot to interfer with the legacy test suite
# based on minitest
config.generators do |g|
g.factory_girl false
g.factory_bot false
g.test_framework :rspec
end

Expand Down
12 changes: 6 additions & 6 deletions src/api/spec/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ We are using the standard [RSpec generators](https://relishapp.com/rspec/rspec-r
`rails generate rspec:model package` or
`rails generate rspec:controller webui::blah`

### Factory Girl
We use [Factory Girl](https://github.com/thoughtbot/factory_girl_rails) to create our ruby objects, make sure to get familiar with the factory girl [features and syntax](http://www.rubydoc.info/gems/factory_girl/file/GETTING_STARTED.md).
### Factory Bot
We use [Factory Bot](https://github.com/thoughtbot/factory_bot_rails) to create our ruby objects, make sure to get familiar with the factory bot [features and syntax](http://www.rubydoc.info/gems/factory_bot/file/GETTING_STARTED.md).
Be aware of that factories, other than fixtures, run through ActiveRecord validations.
All OBS factories reside in `spec/factories`.

Expand All @@ -72,10 +72,10 @@ For creating has_many associations we prefer ```create_list```:
project.packages = create_list(:package, 2)
```

Please also have a look at the [factory girl documentation](https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md#associations)
Please also have a look at the [factory bot documentation](https://github.com/thoughtbot/factory_bot/blob/master/GETTING_STARTED.md#associations)

#### Use a sequence for unique values
It's necessary to use a [sequence](https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md#sequences) for attributes which have to be unique like project.title or user.login.
It's necessary to use a [sequence](https://github.com/thoughtbot/factory_bot/blob/master/GETTING_STARTED.md#sequences) for attributes which have to be unique like project.title or user.login.

```
sequence(:login) { |n| "user_#{n}" }
Expand All @@ -91,7 +91,7 @@ let!(:user) { create(:confirmed_user, login: "proxy_user") }
By passing ```login: "proxy_user"``` to the create statement, the username is now always proxy_user and not random (e.g. user_42).

#### Factories should be the bare minimum
Different to fixtures, factory girl runs through your ActiveRecord validations.
Different to fixtures, factory bot runs through your ActiveRecord validations.
That said, only add the bare minimum to your factory which is required to be valid.
You can use an inherited factory to add or override attributes.

Expand All @@ -110,7 +110,7 @@ You can use an inherited factory to add or override attributes.
See this [blog article](https://robots.thoughtbot.com/factories-should-be-the-bare-minimum) for a detailed explanation.

#### When Transient Attributes make sense
Use [transient attributes](https://github.com/thoughtbot/factory_girl/blob/master/GETTING_STARTED.md#transient-attributes) to DRY your factories.
Use [transient attributes](https://github.com/thoughtbot/factory_bot/blob/master/GETTING_STARTED.md#transient-attributes) to DRY your factories.

```
factory :project_with_package do
Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/factories/architecture.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :architecture do
sequence(:name) { |n| "arch_factory_#{n}" }
end
Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/factories/attrib_allowed_values.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :attrib_allowed_value do
end
end
2 changes: 1 addition & 1 deletion src/api/spec/factories/attrib_default_values.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :attrib_default_value do
attrib_type { create(:attrib_type) }
position 1
Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/factories/attrib_namespaces.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :attrib_namespace do
name { Faker::Lorem.word }
end
Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/factories/attrib_types.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :attrib_type do
sequence(:name) { |n| "attribute_factory_#{n}" }
attrib_namespace
Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/factories/attrib_values.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :attrib_value do
attrib
# this is necessary! otherwise the default value will not be recognized.
Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/factories/attribs.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :attrib do
attrib_type
project
Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/factories/bs_request_actions.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :bs_request_action do
factory :bs_request_action_add_maintainer_role do
type 'add_role'
Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/factories/bs_requests.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :bs_request do
description { Faker::Lorem.paragraph }
state "new"
Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/factories/comments.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :comment do
body { Faker::Lorem.paragraph }
user
Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/factories/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :configuration do
name { Faker::Lorem.word }
title { Faker::Lorem.word }
Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/factories/distribution.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :distribution do
vendor { Faker::Lorem.word }
version "13.2"
Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/factories/download_repository_factory.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :download_repository do
arch "x86_64"
url "http://suse.com"
Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/factories/event_subscriptions.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :event_subscription do
factory :event_subscription_comment_for_project do
eventtype 'Event::CommentForProject'
Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/factories/flag.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :flag do
project
position 1
Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/factories/group_maintainers.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :group_maintainer do
user { create(:user) }
group { create(:group) }
Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/factories/groups.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :group do
sequence(:title){ |n| "group_#{n}" }
email { Faker::Internet.email }
Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/factories/groups_user.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :groups_user do
user { create(:user) }
group { create(:group) }
Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/factories/history_elements.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :history_element_review_assigned, class: 'HistoryElement::ReviewAssigned' do
type { 'HistoryElement::ReviewAssigned' }
end
Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/factories/issue.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :issue do
name Faker::Lorem.words(5).join(' ')

Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/factories/issue_tracker.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :issue_tracker do
name Faker::Lorem.words(5).join(' ')
kind 'github'
Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/factories/kiwi_description.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :kiwi_description, class: Kiwi::Description do
association :image, factory: :kiwi_image

Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/factories/kiwi_image.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :kiwi_image, class: Kiwi::Image do
name { Faker::Name.name }
md5_last_revision nil
Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/factories/kiwi_package.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :kiwi_package, class: Kiwi::Package do
transient do
image { create(:kiwi_image) }
Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/factories/kiwi_package_group.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :kiwi_package_group, class: Kiwi::PackageGroup do
association :image, factory: :kiwi_image

Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/factories/kiwi_repository.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :kiwi_repository, class: Kiwi::Repository do
association :image, factory: :kiwi_image

Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/factories/maintained_project.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :maintained_project do
project
maintenance_project
Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/factories/notification.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :notification do
event_type 'FakeEventType'
event_payload { { fake: 'payload' } }
Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/factories/package_issue.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :package_issue do
end
end
2 changes: 1 addition & 1 deletion src/api/spec/factories/packages.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :package do
project
sequence(:name) { |n| "package_#{n}" }
Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/factories/path_element.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :path_element do
sequence(:position) { |n| n }
repository
Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/factories/project.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :project do
sequence(:name) { |n| "project_#{n}" }
title { Faker::Book.title }
Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/factories/project_log_entry.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :project_log_entry do
project
datetime { Time.zone.today }
Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/factories/relationship.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :relationship do
role { Role.find_by_title('maintainer') }

Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/factories/release_target.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :release_target do
repository
target_repository { create(:repository) }
Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/factories/repository.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :repository do
project
sequence(:name) { |n| "repository_#{n}" }
Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/factories/repository_architecture.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :repository_architecture do
repository
architecture
Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/factories/review.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :review do
state :new

Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/factories/role.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :role do
sequence(:title) { |n| "role_#{n}" }
end
Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/factories/status_history.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :status_history do
transient do
source 'source'
Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/factories/status_message.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :status_message do
message { Faker::Lorem.paragraph }
severity "Green"
Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/factories/users.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :user do
email { Faker::Internet.email }
realname { Faker::Name.name }
Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/factories/watched_projects.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :watched_project do
project
user
Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/rails_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
end

# support fixtures
require 'support/factory_girl'
require 'support/factory_bot'

# support database cleanup
require 'support/database_cleaner'
Expand Down
2 changes: 1 addition & 1 deletion src/api/spec/support/database_cleaner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
architectures attrib_types
attrib_namespaces issue_trackers).freeze

# We are using factory_girl to set up everything the test needs up front,
# We are using factory_bot to set up everything the test needs up front,
# instead of loading a set of fixtures in the beginning of the suite
config.use_transactional_fixtures = false

Expand Down
3 changes: 3 additions & 0 deletions src/api/spec/support/factory_bot.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
RSpec.configure do |config|
config.include FactoryBot::Syntax::Methods
end
3 changes: 0 additions & 3 deletions src/api/spec/support/factory_girl.rb

This file was deleted.

0 comments on commit 1d23619

Please sign in to comment.