Skip to content

Commit

Permalink
upgrade FactoryGirl to FactoryBot
Browse files Browse the repository at this point in the history
Because the latest is a good thing to have.

Because it's the right thing to do.

Because there will probably be some factory shenanigans with a Rails 5.0
to 5.1 upgrade.

Also moves factorybot and faker to the development & test group because
they are sometimes handy in the development environment for cobbling up
test data.

Also also alphabetized the test group because rubocop likes that.

Also also also, resolve deprecation warning about static attributes in
factories.

Signed-off-by: Robb Kidd <rkidd@chef.io>
  • Loading branch information
robbkidd committed Oct 29, 2018
1 parent 80f9cdd commit ce44f9c
Show file tree
Hide file tree
Showing 28 changed files with 95 additions and 97 deletions.
10 changes: 4 additions & 6 deletions src/supermarket/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ group :doc do
end

group :development do
gem 'faker'
gem 'guard'
gem 'guard-rspec', require: false
gem 'guard-rubocop', require: false
Expand All @@ -69,13 +68,10 @@ end
group :test do
gem 'capybara'
gem 'capybara-screenshot'
gem 'factory_girl_rails', require: false
gem 'poltergeist'

gem 'shoulda-matchers', '~> 2.8'

gem 'database_cleaner'
gem 'poltergeist'
gem 'rails-controller-testing'
gem 'shoulda-matchers', '~> 2.8'
gem 'vcr', require: false
gem 'webmock', require: false
end
Expand All @@ -84,6 +80,8 @@ group :development, :test do
gem 'brakeman'
gem 'bundler-audit', git: 'https://github.com/rubysec/bundler-audit.git', ref: '4e32fca'
gem 'byebug'
gem 'factory_bot_rails', require: false
gem 'faker'
gem 'launchy'
gem 'mail_view'
gem 'pry-rails'
Expand Down
8 changes: 4 additions & 4 deletions src/supermarket/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -185,10 +185,10 @@ GEM
et-orbi (1.1.5)
tzinfo
execjs (2.7.0)
factory_girl (4.8.0)
factory_bot (4.11.1)
activesupport (>= 3.0.0)
factory_girl_rails (4.8.0)
factory_girl (~> 4.8.0)
factory_bot_rails (4.11.1)
factory_bot (~> 4.11.1)
railties (>= 3.0.0)
faker (1.7.3)
i18n (~> 0.5)
Expand Down Expand Up @@ -609,7 +609,7 @@ DEPENDENCIES
database_cleaner
ddtrace
dotenv
factory_girl_rails
factory_bot_rails
faker
fieri!
foreman
Expand Down
4 changes: 2 additions & 2 deletions src/supermarket/spec/factories/account.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FactoryGirl.define do
FactoryBot.define do
factory :account do
association :user
uid { username }
sequence(:username) { |n| "johndoe#{n}" }
provider 'github'
provider { 'github' }
oauth_token { SecureRandom.hex(15) }
oauth_secret { SecureRandom.hex(20) }
oauth_expires { 10.days.from_now }
Expand Down
4 changes: 2 additions & 2 deletions src/supermarket/spec/factories/category.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
FactoryGirl.define do
FactoryBot.define do
factory :category do
name 'Other'
name { 'Other' }
end
end
2 changes: 1 addition & 1 deletion src/supermarket/spec/factories/collaborator.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :cookbook_collaborator, class: 'Collaborator' do
association :resourceable, factory: :cookbook
association :user
Expand Down
14 changes: 7 additions & 7 deletions src/supermarket/spec/factories/cookbook.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
FactoryGirl.define do
FactoryBot.define do
factory :cookbook do
association :category
association :owner, factory: :user
sequence(:name) { |n| "redis-#{n}" }
source_url 'http://example.com'
issues_url 'http://example.com/issues'
deprecated false
featured false
source_url { 'http://example.com' }
issues_url { 'http://example.com/issues' }
deprecated { false }
featured { false }

transient do
cookbook_versions_count 2
cookbook_versions_count { 2 }
end

before(:create) do |cookbook, evaluator|
Expand All @@ -18,7 +18,7 @@

factory :partner_cookbook do
sequence(:name) { |n| "partner-#{n}" }
badges_mask 1
badges_mask { 1 }
end
end
end
6 changes: 3 additions & 3 deletions src/supermarket/spec/factories/cookbook_dependency.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FactoryGirl.define do
FactoryBot.define do
factory :cookbook_dependency do
association :cookbook_version
association :cookbook

name 'apt'
version_constraint '>= 0.1.0'
name { 'apt' }
version_constraint { '>= 0.1.0' }
end
end
2 changes: 1 addition & 1 deletion src/supermarket/spec/factories/cookbook_follower.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :cookbook_follower do
association :cookbook
association :user
Expand Down
10 changes: 5 additions & 5 deletions src/supermarket/spec/factories/cookbook_version.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
FactoryGirl.define do
FactoryBot.define do
factory :cookbook_version do
association :user
description 'An awesome cookbook!'
license 'MIT'
description { 'An awesome cookbook!' }
license { 'MIT' }
sequence(:version) { |n| "1.2.#{n}" }
tarball { File.open('spec/support/cookbook_fixtures/redis-test-v1.tgz') }
readme '# redis cookbook'
readme_extension 'md'
readme { '# redis cookbook' }
readme_extension { 'md' }

trait :debian do
after(:build) do |cookbook_version, evaluator|
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :cookbook_version_platform do
association :cookbook_version
association :supported_platform
Expand Down
4 changes: 2 additions & 2 deletions src/supermarket/spec/factories/email.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FactoryGirl.define do
FactoryBot.define do
factory :email do
association :user
email { "#{user.username}@example.com" }
confirmation_token 'ABCD1234'
confirmation_token { 'ABCD1234' }
confirmed_at { 1.day.ago }
end
end
2 changes: 1 addition & 1 deletion src/supermarket/spec/factories/email_preference.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :email_preference do
association :user
association :system_email
Expand Down
2 changes: 1 addition & 1 deletion src/supermarket/spec/factories/group.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(:name) { |n| "My Group #{n}" }
end
Expand Down
6 changes: 3 additions & 3 deletions src/supermarket/spec/factories/group_member.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FactoryGirl.define do
FactoryBot.define do
factory :group_member do
association :user
association :group
admin nil
admin { nil }

factory :admin_group_member, class: GroupMember do
admin true
admin { true }
end
end
end
2 changes: 1 addition & 1 deletion src/supermarket/spec/factories/group_resource.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :group_resource do
association :group
association :resourceable, factory: :cookbook
Expand Down
8 changes: 4 additions & 4 deletions src/supermarket/spec/factories/icla.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
FactoryGirl.define do
FactoryBot.define do
factory :icla do
head 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod'
body 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod'
version ENV['ICLA_VERSION']
head { 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod' }
body { 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod' }
version { ENV['ICLA_VERSION'] }
end
end
30 changes: 15 additions & 15 deletions src/supermarket/spec/factories/icla_signature.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
FactoryGirl.define do
FactoryBot.define do
factory :icla_signature do
association :user

prefix 'Mr.'
first_name 'John'
middle_name 'A.'
last_name 'Doe'
suffix 'Sr.'
phone '1234567890'
email 'jdoe@example.com'
prefix { 'Mr.' }
first_name { 'John' }
middle_name { 'A.' }
last_name { 'Doe' }
suffix { 'Sr.' }
phone { '1234567890' }
email { 'jdoe@example.com' }

address_line_1 '123 Some Street'
address_line_2 'Apartment #5'
city 'Pittsburgh'
state 'PA'
zip '15213'
country 'United States'
address_line_1 { '123 Some Street' }
address_line_2 { 'Apartment #5' }
city { 'Pittsburgh' }
state { 'PA' }
zip { '15213' }
country { 'United States' }

agreement '1'
agreement { '1' }
end
end
6 changes: 3 additions & 3 deletions src/supermarket/spec/factories/invitation.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FactoryGirl.define do
FactoryBot.define do
factory :invitation do
association :organization
token 'ABCD1234'
admin true
token { 'ABCD1234' }
admin { true }

sequence(:email) { |n| "johndoe#{n}@example.com" }
end
Expand Down
6 changes: 3 additions & 3 deletions src/supermarket/spec/factories/metric_result.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
FactoryGirl.define do
FactoryBot.define do
factory :metric_result, class: 'MetricResult' do
association :cookbook_version
association :quality_metric
failure true
feedback 'it failed'
failure { true }
feedback { 'it failed' }
end
end
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :ownership_transfer_request do
association :cookbook
association :recipient, factory: :user
Expand Down
20 changes: 10 additions & 10 deletions src/supermarket/spec/factories/quality_metric.rb
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
FactoryGirl.define do
FactoryBot.define do
factory :quality_metric, class: 'QualityMetric' do
trait :foodcritic do
name "Foodcritic"
name { "Foodcritic" }
end

trait :collaborator_num do
name "Collaborator Number"
name { "Collaborator Number" }
end

trait :publish do
name "Publish"
name { "Publish" }
end

trait :license do
name "License"
name { "License" }
end

trait :supported_platforms do
name "Supported Platforms"
name { "Supported Platforms" }
end

trait :contributing_file do
name "Contributing File"
name { "Contributing File" }
end

trait :testing_file do
name "Testing File"
name { "Testing File" }
end

trait :version_tag do
name "Version Tag"
name { "Version Tag" }
end

trait :no_binaries do
name "No Binaries"
name { "No Binaries" }
end

factory :foodcritic_metric, traits: [:foodcritic]
Expand Down
6 changes: 3 additions & 3 deletions src/supermarket/spec/factories/supported_platform.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
FactoryGirl.define do
FactoryBot.define do
factory :supported_platform do
name 'ubuntu'
version_constraint '>= 12.04'
name { 'ubuntu' }
version_constraint { '>= 12.04' }
end
end
2 changes: 1 addition & 1 deletion src/supermarket/spec/factories/system_email.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FactoryGirl.define do
FactoryBot.define do
factory :system_email do
sequence(:name) { |n| "Awesome Email #{n}" }
end
Expand Down
10 changes: 5 additions & 5 deletions src/supermarket/spec/factories/tool.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
FactoryGirl.define do
FactoryBot.define do
factory :tool do
association :owner, factory: :user
sequence(:name) { |n| "butter-#{n}" }
type 'ohai_plugin'
description 'Great plugin for ohai.'
source_url 'http://example.com'
instructions 'Use with caution.'
type { 'ohai_plugin' }
description { 'Great plugin for ohai.' }
source_url { 'http://example.com' }
instructions { 'Use with caution.' }
end
end
14 changes: 7 additions & 7 deletions src/supermarket/spec/factories/user.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
FactoryGirl.define do
FactoryBot.define do
factory :user do
first_name 'John'
last_name 'Doe'
first_name { 'John' }
last_name { 'Doe' }
public_key { File.read('spec/support/key_fixtures/valid_public_key.pub') }

sequence(:email) { |n| "johndoe#{n}@example.com" }

transient do
create_chef_account true
create_chef_account { true }
end

after(:create) do |user, evaluator|
Expand All @@ -17,9 +17,9 @@
end

factory :admin, class: User do
first_name 'Admin'
last_name 'User'
roles_mask 1
first_name { 'Admin' }
last_name { 'User' }
roles_mask { 1 }
end
end
end
Loading

0 comments on commit ce44f9c

Please sign in to comment.