Skip to content

Commit

Permalink
DS-4969 Update data_works gem for Rails 5.2.6; Upgrade FactoryGirl to…
Browse files Browse the repository at this point in the history
… FactoryBot
  • Loading branch information
denniscdmc committed Aug 18, 2021
1 parent afc5090 commit 88aa5b8
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 29 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
.bundle
.config
.yardoc
.ruby-gemset
Gemfile.lock
Guardfile
InstalledFiles
Expand Down
1 change: 1 addition & 0 deletions .ruby-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ruby-2.6.5
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -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:
Expand Down Expand Up @@ -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.

Expand All @@ -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

Expand Down Expand Up @@ -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.
Expand Down
28 changes: 15 additions & 13 deletions data_works.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,29 @@ 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"]

s.files = `git ls-files`.split("\n")
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
2 changes: 1 addition & 1 deletion lib/data_works/grafter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/data_works/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module DataWorks
VERSION = "0.1.2"
VERSION = "0.1.3"
end

8 changes: 4 additions & 4 deletions spec/factories/factories.rb
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion spec/helper/data_works_spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ class TheDataWorks < DataWorks::Base
end

RSpec.configure do |config|
config.include FactoryGirl::Syntax::Methods
config.include FactoryBot::Syntax::Methods
end
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -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'
Expand Down

0 comments on commit 88aa5b8

Please sign in to comment.