Skip to content

Commit 6f019e0

Browse files
Copilotscarroll32
andauthored
Replace blueprints with FactoryBot (#1595)
* Initial plan * Initial analysis of Ransack spec structure - planning refactor from Machinist to FactoryBot Co-authored-by: scarroll32 <[email protected]> * Changes before error encountered Co-authored-by: scarroll32 <[email protected]> * Complete replacement of Machinist with FactoryBot - Replace Machinist gem with FactoryBot in Gemfile - Convert all blueprint files to FactoryBot factories with proper syntax - Update spec_helper.rb to use FactoryBot instead of Machinist/Sham - Update console.rb to use FactoryBot - Update schema.rb data seeding to use FactoryBot instead of .make methods - Remove old blueprint files and unused dummy app structure - All tests passing (437/438 pass, 1 expected failure, same as original) - FactoryBot factories work correctly with polymorphic associations Co-authored-by: scarroll32 <[email protected]> * Replace Machinist with FactoryBot * Include Rubocop in manual spec runs --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: scarroll32 <[email protected]> Co-authored-by: Sean <[email protected]>
1 parent 3d985fd commit 6f019e0

File tree

17 files changed

+63
-71
lines changed

17 files changed

+63
-71
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ coverage/*
88
.byebug_history
99
vendor/bundle
1010
.idea
11+

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ Here's a quick guide:
8383
A one-liner to run all three
8484

8585
```sh
86-
bundle exec rake spec && DB=pg bundle exec rake spec && DB=mysql bundle exec rake spec
86+
bundle exec rubocop && bundle exec rake spec && DB=pg bundle exec rake spec && DB=mysql bundle exec rake spec
8787
```
8888

8989
For Postgres and MySQL, databases are expected to exist, called 'ransack'. To create use these commands (assuming OS X and Homebrew):

Gemfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ end
5050
gem 'mysql2'
5151

5252
group :test do
53-
gem 'machinist', '~> 1.0.6'
53+
gem 'factory_bot'
5454
gem 'rspec'
5555
gem 'simplecov', require: false
5656
end

spec/blueprints/articles.rb

Lines changed: 0 additions & 5 deletions
This file was deleted.

spec/blueprints/comments.rb

Lines changed: 0 additions & 5 deletions
This file was deleted.

spec/blueprints/notes.rb

Lines changed: 0 additions & 5 deletions
This file was deleted.

spec/blueprints/people.rb

Lines changed: 0 additions & 8 deletions
This file was deleted.

spec/blueprints/tags.rb

Lines changed: 0 additions & 3 deletions
This file was deleted.

spec/console.rb

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,13 @@
11
Bundler.setup
2-
require 'machinist/active_record'
3-
require 'sham'
2+
require 'factory_bot'
43
require 'faker'
54
require 'ransack'
65

7-
Dir[File.expand_path('../../spec/{helpers,support,blueprints}/*.rb', __FILE__)]
6+
Dir[File.expand_path('../../spec/{helpers,support,factories}/*.rb', __FILE__)]
87
.each do |f|
98
require f
109
end
1110

12-
Sham.define do
13-
name { Faker::Name.name }
14-
title { Faker::Lorem.sentence }
15-
body { Faker::Lorem.paragraph }
16-
salary { |index| 30000 + (index * 1000) }
17-
tag_name { Faker::Lorem.words(number: 3).join(' ') }
18-
note { Faker::Lorem.words(number: 7).join(' ') }
19-
only_admin { Faker::Lorem.words(number: 3).join(' ') }
20-
only_search { Faker::Lorem.words(number: 3).join(' ') }
21-
only_sort { Faker::Lorem.words(number: 3).join(' ') }
22-
notable_id { |id| id }
23-
end
11+
Faker::Config.random = Random.new(0)
2412

2513
Schema.create

spec/factories/articles.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FactoryBot.define do
2+
factory :article do
3+
association :person
4+
title { Faker::Lorem.sentence }
5+
body { Faker::Lorem.paragraph }
6+
end
7+
end

0 commit comments

Comments
 (0)