From 88aa5b858e629a9578d5684d2a1763c1490431ec Mon Sep 17 00:00:00 2001 From: Dennis Chan Date: Wed, 28 Jul 2021 10:08:47 -0400 Subject: [PATCH] DS-4969 Update data_works gem for Rails 5.2.6; Upgrade FactoryGirl to FactoryBot --- .gitignore | 1 + .ruby-version | 1 + README.md | 16 +++++++-------- data_works.gemspec | 28 ++++++++++++++------------- lib/data_works/grafter.rb | 2 +- lib/data_works/version.rb | 2 +- spec/factories/factories.rb | 8 ++++---- spec/helper/data_works_spec_helper.rb | 2 +- spec/spec_helper.rb | 2 +- 9 files changed, 33 insertions(+), 29 deletions(-) create mode 100644 .ruby-version diff --git a/.gitignore b/.gitignore index d5c9bd9..7d91ec8 100644 --- a/.gitignore +++ b/.gitignore @@ -3,6 +3,7 @@ .bundle .config .yardoc +.ruby-gemset Gemfile.lock Guardfile InstalledFiles diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..d7edb56 --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +ruby-2.6.5 diff --git a/README.md b/README.md index 75016c5..500abcd 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # DataWorks -DataWorks makes it easier to work with FactoryGirl in the context of a complex +DataWorks makes it easier to work with FactoryBot in the context of a complex data model. DataWorks has these benefits: @@ -155,8 +155,8 @@ parent models. DataWorks solves this problem by following one simple rule: **by default, reuse objects that already exist.** -When using FactoryGirl, a factory only concerns itself with its particular -neighborhood of the data model. Since FactoryGirl factories do not know +When using FactoryBot, a factory only concerns itself with its particular +neighborhood of the data model. Since FactoryBot factories do not know the big picture, their default is not to reuse existing objects but create new ones. This results in the proliferation of unwanted objects. @@ -166,9 +166,9 @@ reuse objects that already exist unless explicitly told otherwise. ### Implementation -DataWorks exists as a layer on top of FactoryGirl. DataWorks assumes that -you have FactoryGirl factories for each model and that they create valid -objects. DataWorks always uses a create strategy with FactoryGirl. +DataWorks exists as a layer on top of FactoryBot. DataWorks assumes that +you have FactoryBot factories for each model and that they create valid +objects. DataWorks always uses a create strategy with FactoryBot. ### Benefits @@ -458,8 +458,8 @@ end ``` `config.necessary_parents` is where you tell DataWorks which other factories -must be created when you create a particular factory. Because FactoryGirl -causes a proliferation of extra objects, DataWorks does not allow FactoryGirl +must be created when you create a particular factory. Because FactoryBot +causes a proliferation of extra objects, DataWorks does not allow FactoryBot to create necessary associated objects. Instead, DataWorks will create the necessary parent objects and pass them down into the factory, ensuring that too many parent objects do not get created. diff --git a/data_works.gemspec b/data_works.gemspec index 01da266..b4ab8d0 100644 --- a/data_works.gemspec +++ b/data_works.gemspec @@ -9,7 +9,7 @@ Gem::Specification.new do |s| s.authors = ["Wyatt Greene", "Anne Geiersbach", "Dennis Chan", "Luke Inglis"] s.email = ["dev@dmgroupk12.com"] s.summary = %q{Reducing the complexity of testing complex data models } - s.description = %q{DataWorks makes it easier to work with FactoryGirl in the context of a complex data model.} + s.description = %q{DataWorks makes it easier to work with FactoryBot in the context of a complex data model.} s.homepage = 'https://github.com/dmcouncil/data_works' s.licenses = ["MIT", "Copyright (c) 2018 District Management Group"] @@ -17,19 +17,21 @@ Gem::Specification.new do |s| s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") s.require_paths = ["lib"] - s.add_dependency "activerecord", "~> 4.1" - s.add_dependency "activesupport", "~> 4.1" - s.add_dependency 'factory_girl', '>= 3.0' + # Most of the below must match the rails app + + s.add_dependency 'activerecord', '5.2.6' + s.add_dependency 'activesupport', '5.2.6' + s.add_dependency 'factory_bot' s.add_dependency 'graphviz', '~> 0.1.0' s.add_dependency 'launchy', '~> 2.4' - s.add_development_dependency "bundler", "~> 1.9" - s.add_development_dependency "rake" - s.add_development_dependency "database_cleaner", "~> 1.4.0" - s.add_development_dependency "rspec" - s.add_development_dependency "sqlite3" - s.add_development_dependency "pry" - s.add_development_dependency "guard" - s.add_development_dependency "guard-rspec" - s.add_development_dependency "active_hash", "~> 1.5.0" + s.add_development_dependency 'bundler' + s.add_development_dependency 'rake' + s.add_development_dependency 'database_cleaner' + s.add_development_dependency 'rspec' + s.add_development_dependency 'sqlite3' + s.add_development_dependency 'pry' + s.add_development_dependency 'guard' + s.add_development_dependency 'guard-rspec' + s.add_development_dependency 'active_hash' end diff --git a/lib/data_works/grafter.rb b/lib/data_works/grafter.rb index 4dc3bbc..7b70a79 100644 --- a/lib/data_works/grafter.rb +++ b/lib/data_works/grafter.rb @@ -11,7 +11,7 @@ def initialize(works, model_name, model_attrs) def create_model_and_its_necessary_parents created_parents = @parent_creator.create_necessary_parents(parents_we_already_have) - FactoryGirl.create(@model_name, @model_attrs.merge(created_parents)) + FactoryBot.create(@model_name, @model_attrs.merge(created_parents)) end private diff --git a/lib/data_works/version.rb b/lib/data_works/version.rb index af44837..b834ec4 100644 --- a/lib/data_works/version.rb +++ b/lib/data_works/version.rb @@ -1,4 +1,4 @@ module DataWorks - VERSION = "0.1.2" + VERSION = "0.1.3" end diff --git a/spec/factories/factories.rb b/spec/factories/factories.rb index a95ce2e..eb9f283 100644 --- a/spec/factories/factories.rb +++ b/spec/factories/factories.rb @@ -1,13 +1,13 @@ require_relative '../lib/data_faker' -FactoryGirl.define do +FactoryBot.define do factory :pet do name { fake_string } kind { animal_types.sample } birth_year { (1914..2014).to_a.sample } trait :bird do - kind 'Bird' + kind { 'Bird' } end factory :pet_bird, traits: [:bird] @@ -47,11 +47,11 @@ name { "#{%w(Fluffy Rubber Squeeky).sample} #{%w(Ball Stick Shoe Book).sample}" } trait :hooman do - kind 'Robot Vacuum' # you know the one + kind { 'Robot Vacuum' } # you know the one end trait :bell do - kind 'Bell' + kind { 'Bell' } end factory :hooman_toy, traits: [:hooman] diff --git a/spec/helper/data_works_spec_helper.rb b/spec/helper/data_works_spec_helper.rb index 2d76c45..8cbb14a 100644 --- a/spec/helper/data_works_spec_helper.rb +++ b/spec/helper/data_works_spec_helper.rb @@ -42,5 +42,5 @@ class TheDataWorks < DataWorks::Base end RSpec.configure do |config| - config.include FactoryGirl::Syntax::Methods + config.include FactoryBot::Syntax::Methods end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0d12db7..7e1cc94 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,7 +1,7 @@ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) require 'active_support/all' require 'active_support/testing/time_helpers' -require 'factory_girl' +require 'factory_bot' require 'database_cleaner' require 'active_hash' require 'sqlite3'