-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit f722b6c
Showing
17 changed files
with
868 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: CI | ||
|
||
on: [push] | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
ruby: | ||
- "2.6" | ||
- "2.7" | ||
- "3.0" | ||
|
||
name: Ruby ${{ matrix.ruby }} | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: ruby/setup-ruby@v1 | ||
with: | ||
ruby-version: ${{ matrix.ruby }} | ||
- uses: actions/cache@v2 | ||
with: | ||
path: vendor/bundle | ||
key: ${{ runner.os }}-${{ matrix.ruby }}-gems-${{ hashFiles('**/Gemfile.lock') }} | ||
restore-keys: | | ||
${{ runner.os }}-${{ matrix.ruby }}-gems- | ||
- name: Run the tests and lint the code | ||
env: | ||
COVERAGE: true | ||
run: | | ||
gem install bundler | ||
bundle config path vendor/bundle | ||
bundle install --jobs 4 --retry 3 | ||
bundle exec rake spec | ||
bundle exec rubocop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
require: | ||
- rubocop-performance | ||
- rubocop-rake | ||
- rubocop-rspec | ||
|
||
AllCops: | ||
NewCops: enable | ||
TargetRubyVersion: 2.6 | ||
|
||
Layout/HashAlignment: | ||
EnforcedColonStyle: table | ||
EnforcedHashRocketStyle: table | ||
|
||
Metrics/BlockLength: | ||
Exclude: | ||
- factory.gemspec | ||
- spec/**/*_spec.rb | ||
|
||
Naming/RescuedExceptionsVariableName: | ||
PreferredName: error | ||
|
||
Naming/VariableNumber: | ||
EnforcedStyle: snake_case | ||
|
||
RSpec/ExampleLength: | ||
Max: 20 | ||
|
||
RSpec/FilePath: | ||
Enabled: false | ||
|
||
RSpec/MultipleDescribes: | ||
Enabled: false | ||
|
||
Style/DocumentationMethod: | ||
Enabled: true | ||
RequireForNonPublicMethods: true | ||
|
||
Style/GuardClause: | ||
Enabled: false | ||
|
||
Style/PercentLiteralDelimiters: | ||
PreferredDelimiters: | ||
"%w": "()" | ||
|
||
Style/RaiseArgs: | ||
EnforcedStyle: compact | ||
|
||
Style/StringLiterals: | ||
EnforcedStyle: double_quotes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Changelog | ||
|
||
## 0.1.0 — November 5th, 2021 | ||
|
||
* Initial release. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
source "https://rubygems.org" | ||
|
||
gemspec | ||
|
||
group :deelopment, :test do | ||
gem "simplecov-console", "0.9.1", require: false | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
factory_manager (0.1.0) | ||
factory_bot (~> 6.0) | ||
|
||
GEM | ||
remote: https://rubygems.org/ | ||
specs: | ||
activemodel (6.1.4.1) | ||
activesupport (= 6.1.4.1) | ||
activerecord (6.1.4.1) | ||
activemodel (= 6.1.4.1) | ||
activesupport (= 6.1.4.1) | ||
activesupport (6.1.4.1) | ||
concurrent-ruby (~> 1.0, >= 1.0.2) | ||
i18n (>= 1.6, < 2) | ||
minitest (>= 5.1) | ||
tzinfo (~> 2.0) | ||
zeitwerk (~> 2.3) | ||
ansi (1.5.0) | ||
ast (2.4.2) | ||
concurrent-ruby (1.1.9) | ||
diff-lcs (1.4.4) | ||
docile (1.4.0) | ||
factory_bot (6.2.0) | ||
activesupport (>= 5.0.0) | ||
i18n (1.8.11) | ||
concurrent-ruby (~> 1.0) | ||
minitest (5.14.4) | ||
parallel (1.21.0) | ||
parser (3.0.2.0) | ||
ast (~> 2.4.1) | ||
rainbow (3.0.0) | ||
rake (13.0.6) | ||
regexp_parser (2.1.1) | ||
rexml (3.2.5) | ||
rspec (3.10.0) | ||
rspec-core (~> 3.10.0) | ||
rspec-expectations (~> 3.10.0) | ||
rspec-mocks (~> 3.10.0) | ||
rspec-core (3.10.1) | ||
rspec-support (~> 3.10.0) | ||
rspec-expectations (3.10.1) | ||
diff-lcs (>= 1.2.0, < 2.0) | ||
rspec-support (~> 3.10.0) | ||
rspec-mocks (3.10.2) | ||
diff-lcs (>= 1.2.0, < 2.0) | ||
rspec-support (~> 3.10.0) | ||
rspec-support (3.10.3) | ||
rubocop (1.22.3) | ||
parallel (~> 1.10) | ||
parser (>= 3.0.0.0) | ||
rainbow (>= 2.2.2, < 4.0) | ||
regexp_parser (>= 1.8, < 3.0) | ||
rexml | ||
rubocop-ast (>= 1.12.0, < 2.0) | ||
ruby-progressbar (~> 1.7) | ||
unicode-display_width (>= 1.4.0, < 3.0) | ||
rubocop-ast (1.12.0) | ||
parser (>= 3.0.1.1) | ||
rubocop-performance (1.12.0) | ||
rubocop (>= 1.7.0, < 2.0) | ||
rubocop-ast (>= 0.4.0) | ||
rubocop-rake (0.6.0) | ||
rubocop (~> 1.0) | ||
rubocop-rspec (2.5.0) | ||
rubocop (~> 1.19) | ||
ruby-progressbar (1.11.0) | ||
simplecov (0.21.2) | ||
docile (~> 1.1) | ||
simplecov-html (~> 0.11) | ||
simplecov_json_formatter (~> 0.1) | ||
simplecov-console (0.9.1) | ||
ansi | ||
simplecov | ||
terminal-table | ||
simplecov-html (0.12.3) | ||
simplecov_json_formatter (0.1.3) | ||
sqlite3 (1.4.2) | ||
terminal-table (3.0.2) | ||
unicode-display_width (>= 1.1.1, < 3) | ||
tzinfo (2.0.4) | ||
concurrent-ruby (~> 1.0) | ||
unicode-display_width (2.1.0) | ||
yard (0.9.26) | ||
zeitwerk (2.5.1) | ||
|
||
PLATFORMS | ||
x86_64-darwin-20 | ||
|
||
DEPENDENCIES | ||
activerecord (= 6.1.4.1) | ||
factory_manager! | ||
rake (= 13.0.6) | ||
rspec (= 3.10.0) | ||
rubocop (= 1.22.3) | ||
rubocop-performance (= 1.12.0) | ||
rubocop-rake (= 0.6.0) | ||
rubocop-rspec (= 2.5.0) | ||
simplecov-console (= 0.9.1) | ||
sqlite3 (= 1.4.2) | ||
yard (= 0.9.26) | ||
|
||
BUNDLED WITH | ||
2.2.25 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License | ||
|
||
Copyright (c) 2021 Tristan Dunn | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the “Software”), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | ||
of the Software, and to permit persons to whom the Software is furnished to do | ||
so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
# factory_manager [![Build Status](https://github.com/tristandunn/factory_manager/workflows/CI/badge.svg)](https://github.com/tristandunn/factory_manager/actions?query=workflow%3ACI) | ||
|
||
A factory manager of factory bots. | ||
|
||
#### Why? | ||
|
||
Creating a deeply nested set of records for seeding or testing can be difficult. | ||
factory_manager creates a DSL based on available [factory_bot][] factories, | ||
allowing deeply nested records to be created easily. | ||
|
||
## Example | ||
|
||
Create a forum, with a single category, a first post for the category, an | ||
administrative user, and one-hundred approved posts by the administrator. | ||
|
||
```ruby | ||
result = FactoryManager.create do | ||
forum do | ||
category(name: "News") do | ||
post(title: "First!") | ||
|
||
self.administrator = administrator = user(:admin) | ||
|
||
post(100, :approved, user: administrator) | ||
end | ||
end | ||
end | ||
|
||
result.administrator | ||
# => User(id: 1, name: "DHH", admin: true) | ||
result.administrator.posts.count | ||
# => 100 | ||
result.administrator.forum.categories.first.posts.count | ||
# => 101 | ||
``` | ||
|
||
<details> | ||
<summary>View the factories for the example.</summary> | ||
|
||
```ruby | ||
FactoryBot.defined do | ||
factory :forum do | ||
name { "Ruby on Rails" } | ||
end | ||
|
||
factory :category do | ||
association :forum | ||
|
||
name { "Announcements" } | ||
end | ||
|
||
factory :user do | ||
association :forum | ||
|
||
name { "DHH" } | ||
|
||
trait :admin do | ||
admin { true } | ||
end | ||
end | ||
|
||
factory :post do | ||
association :category | ||
association :user | ||
|
||
title { "How to install Ruby." } | ||
|
||
trait :approved do | ||
approved { true } | ||
end | ||
end | ||
end | ||
``` | ||
</details> | ||
|
||
<details> | ||
<summary>View the example with inline comments.</summary> | ||
|
||
```ruby | ||
# Starts a manager that will create records. Alternatively user | ||
# +FactoryManager.build+ to build records. | ||
result = FactoryManager.create do | ||
# Creates a +Forum+ record using the default attributes from the factory. | ||
forum do | ||
# Creates a +Category+ record with the default attributes but overrides the | ||
# name. The +category.forum+ association will automatically be set to the | ||
# +Forum+ record created above. | ||
category(name: "News") do | ||
# Create a +Post+ record with a custom title, automatically setting the | ||
# +post.category+ association to the news category created above. | ||
post(title: "First!") | ||
|
||
# Create a +User+ record using the +:admin+ trait. The +user.forum+ | ||
# association will automatically be set to the +Forum+ created above but a | ||
# category will not be assigned. The +self.administrator+ assignment will | ||
# result in the user being available on the +result+ object. | ||
self.administrator = administrator = user(:admin) | ||
|
||
# Create one-hundred +Post+ records using the +:approved+ trait setting | ||
# the +post.user+ association to the administrator user created above and | ||
# the +post.category+ to the news category created above. | ||
post(100, :approved, user: administrator) | ||
end | ||
end | ||
end | ||
``` | ||
</details> | ||
|
||
## License | ||
|
||
factory_manager uses the MIT license. See LICENSE for more details. | ||
|
||
[factory_bot]: https://github.com/thoughtbot/factory_bot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# frozen_string_literal: true | ||
|
||
require "bundler/setup" | ||
require "rspec/core/rake_task" | ||
require "yard" | ||
|
||
Bundler::GemHelper.install_tasks | ||
|
||
RSpec::Core::RakeTask.new do |t| | ||
t.pattern = "spec/**/*_spec.rb" | ||
end | ||
|
||
YARD::Rake::YardocTask.new do |t| | ||
t.files = ["lib/**/*.rb"] | ||
t.options = ["--no-private"] | ||
end | ||
|
||
task default: [:spec] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# frozen_string_literal: true | ||
|
||
Gem::Specification.new do |s| | ||
s.name = "factory_manager" | ||
s.version = "0.1.0" | ||
s.platform = Gem::Platform::RUBY | ||
s.authors = ["Tristan Dunn"] | ||
s.email = "[email protected]" | ||
s.homepage = "https://github.com/tristandunn/factory_manager" | ||
s.summary = "A factory manager of factory bots." | ||
s.description = "A factory manager of factory bots." | ||
s.license = "MIT" | ||
|
||
s.files = Dir["lib/**/*"].to_a | ||
s.test_files = Dir["spec/**/*"].to_a | ||
s.require_path = "lib" | ||
|
||
s.required_ruby_version = ">= 2.6" | ||
|
||
s.add_dependency "factory_bot", "~> 6.0" | ||
|
||
s.add_development_dependency "activerecord", "6.1.4.1" | ||
s.add_development_dependency "rake", "13.0.6" | ||
s.add_development_dependency "rspec", "3.10.0" | ||
s.add_development_dependency "rubocop", "1.22.3" | ||
s.add_development_dependency "rubocop-performance", "1.12.0" | ||
s.add_development_dependency "rubocop-rake", "0.6.0" | ||
s.add_development_dependency "rubocop-rspec", "2.5.0" | ||
s.add_development_dependency "simplecov-console", "0.9.1" | ||
s.add_development_dependency "sqlite3", "1.4.2" | ||
s.add_development_dependency "yard", "0.9.26" | ||
end |
Oops, something went wrong.