pax_global_header00006660000000000000000000000064145277310420014517gustar00rootroot0000000000000052 comment=ac02789e8d229c5fbb125942c6217c76f149db96 factory_bot_rails-6.4.2/000077500000000000000000000000001452773104200152355ustar00rootroot00000000000000factory_bot_rails-6.4.2/.github/000077500000000000000000000000001452773104200165755ustar00rootroot00000000000000factory_bot_rails-6.4.2/.github/ISSUE_TEMPLATE/000077500000000000000000000000001452773104200207605ustar00rootroot00000000000000factory_bot_rails-6.4.2/.github/ISSUE_TEMPLATE/bug_report.md000066400000000000000000000020411452773104200234470ustar00rootroot00000000000000--- name: Bug report about: Create a report to help us improve title: '' labels: 'bug' assignees: '' --- ### Description ### Reproduction Steps ### Expected behavior ### Actual behavior ### System configuration **factory_bot_rails version**: **factory_bot version**: **rails version**: **ruby version**: factory_bot_rails-6.4.2/.github/ISSUE_TEMPLATE/feature_request.md000066400000000000000000000017131452773104200245070ustar00rootroot00000000000000--- name: Feature request about: Suggest an idea for this project title: '' labels: 'feature' assignees: '' --- ### Problem this feature will solve ### Desired solution ## Alternatives considered ## Additional context factory_bot_rails-6.4.2/.github/workflows/000077500000000000000000000000001452773104200206325ustar00rootroot00000000000000factory_bot_rails-6.4.2/.github/workflows/build.yml000066400000000000000000000017041452773104200224560ustar00rootroot00000000000000name: Build on: - push - pull_request jobs: build: name: Ruby ${{ matrix.ruby }} / Rails ${{ matrix.rails }} strategy: fail-fast: false matrix: rails: ["7.0", "6.1"] ruby: ["3.2", "3.1"] include: - rails: "6.1" ruby: "3.0" - rails: "6.1" ruby: "2.7" - rails: "6.0" ruby: "2.7" - rails: "5.2" ruby: "2.7" - rails: "5.2" ruby: "2.6" - rails: "5.1" ruby: "2.6" - rails: "5.0" ruby: "2.5" runs-on: 'ubuntu-latest' env: ARUBA_TIMEOUT: 240 BUNDLE_GEMFILE: gemfiles/rails${{ matrix.rails }}.gemfile steps: - uses: actions/checkout@v2 - uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby }} - name: Setup project run: bundle install - name: Run test run: bundle exec rake factory_bot_rails-6.4.2/.gitignore000066400000000000000000000001751452773104200172300ustar00rootroot00000000000000*.swp .bundle gemfiles/*.lock coverage factory_girl_rails-*.gem pkg rdoc test.db tmp .rubocop-https* factory_bot_rails-*.gem factory_bot_rails-6.4.2/.hound.yml000066400000000000000000000000451452773104200171520ustar00rootroot00000000000000rubocop: config_file: .rubocop.yml factory_bot_rails-6.4.2/.rspec000066400000000000000000000000601452773104200163460ustar00rootroot00000000000000--color --format progress --require spec_helper factory_bot_rails-6.4.2/Appraisals000066400000000000000000000026251452773104200172640ustar00rootroot00000000000000# These are the versions of Rails we want to test against. appraise "rails5.0" do gem "byebug" gem "listen", "~> 3.0.5" gem "puma", "~> 3.0" gem "rails", "~> 5.0.7", ">= 5.0.7.2" gem "spring", "!= 2.1.1" gem "spring-watcher-listen", "~> 2.0.0" gem "sqlite3", "~> 1.3.6" end appraise "rails5.1" do gem "byebug" gem "listen", ">= 3.0.5", "< 3.2" gem "puma", "~> 3.7" gem "rails", "~> 5.1.7" gem "spring", "!= 2.1.1" gem "spring-watcher-listen", "~> 2.0.0" gem "sqlite3", "~> 1.3.6" end appraise "rails5.2" do gem "byebug" gem "listen", ">= 3.0.5", "< 3.2" gem "puma", "~> 3.11" gem "rails", "~> 5.2.4", ">= 5.2.4.2" gem "spring", "!= 2.1.1" gem "spring-watcher-listen", "~> 2.0.0" gem "sqlite3", "~> 1.3.6" end appraise "rails6.0" do gem "byebug" gem "listen", "~> 3.2" gem "puma", "~> 4.1" gem "rails", "~> 6.0.2", ">= 6.0.2.2" gem "spring", "!= 2.1.1" gem "spring-watcher-listen", "~> 2.0.0" gem "sqlite3", "~> 1.4" end appraise "rails6.1" do gem "byebug" gem "listen", "~> 3.2" gem "puma", "~> 5.0" gem "rails", "~> 6.1.0", ">= 6.1.0.0" gem "spring", "!= 2.1.1" gem "spring-watcher-listen", "~> 2.0.0" gem "sqlite3", "~> 1.4" end appraise "rails7.0" do gem "byebug" gem "listen", "~> 3.2" gem "puma", "~> 5.0" gem "rails", "~> 7.0.1", ">= 7.0.1" gem "spring", "!= 2.1.1" gem "spring-watcher-listen", "~> 2.0.0" gem "sqlite3", "~> 1.4" end factory_bot_rails-6.4.2/CODE_OF_CONDUCT.md000066400000000000000000000002511452773104200200320ustar00rootroot00000000000000# Code of conduct By participating in this project, you agree to abide by the [thoughtbot code of conduct][1]. [1]: https://thoughtbot.com/open-source-code-of-conduct factory_bot_rails-6.4.2/CONTRIBUTING.md000066400000000000000000000021121452773104200174620ustar00rootroot00000000000000# Contributing We love pull requests from everyone. By participating in this project, you agree to abide by the thoughtbot [code of conduct]. [code of conduct]: https://thoughtbot.com/open-source-code-of-conduct Fork, then clone the repo: git clone git@github.com:your-username/factory_bot_rails.git Set up your machine: ./bin/setup Make sure the tests pass: rake Make your change. Add tests for your change. Make the tests pass: rake Push to your fork and [submit a pull request][pr]. [pr]: https://github.com/thoughtbot/factory_bot_rails/compare/ At this point you're waiting on us. We like to at least comment on pull requests within three business days (and, typically, one business day). We may suggest some changes or improvements or alternatives. Some things that will increase the chance that your pull request is accepted: * Write tests. * Follow our [style guide][style]. * Write a [good commit message][commit]. [style]: https://github.com/thoughtbot/guides/tree/main/general [commit]: http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html factory_bot_rails-6.4.2/Gemfile000066400000000000000000000002311452773104200165240ustar00rootroot00000000000000source "https://rubygems.org" gemspec name: "factory_bot_rails" gem "appraisal" gem "aruba" gem "cucumber" gem "rake" gem "rspec-rails" gem "standard" factory_bot_rails-6.4.2/Gemfile.lock000066400000000000000000000114561452773104200174660ustar00rootroot00000000000000PATH remote: . specs: factory_bot_rails (6.4.0) factory_bot (~> 6.4) railties (>= 5.0.0) GEM remote: https://rubygems.org/ specs: actionpack (7.0.4.3) actionview (= 7.0.4.3) activesupport (= 7.0.4.3) rack (~> 2.0, >= 2.2.0) rack-test (>= 0.6.3) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.0, >= 1.2.0) actionview (7.0.4.3) activesupport (= 7.0.4.3) builder (~> 3.1) erubi (~> 1.4) rails-dom-testing (~> 2.0) rails-html-sanitizer (~> 1.1, >= 1.2.0) activemodel (7.0.4.3) activesupport (= 7.0.4.3) activerecord (7.0.4.3) activemodel (= 7.0.4.3) activesupport (= 7.0.4.3) activesupport (7.0.4.3) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) tzinfo (~> 2.0) appraisal (2.4.1) bundler rake thor (>= 0.14.0) aruba (2.1.0) bundler (>= 1.17, < 3.0) childprocess (>= 2.0, < 5.0) contracts (>= 0.16.0, < 0.18.0) cucumber (>= 4.0, < 9.0) rspec-expectations (~> 3.4) thor (~> 1.0) ast (2.4.2) builder (3.2.4) childprocess (4.1.0) concurrent-ruby (1.2.2) contracts (0.17) crass (1.0.6) cucumber (8.0.0) builder (~> 3.2, >= 3.2.4) cucumber-ci-environment (~> 9.0, >= 9.0.4) cucumber-core (~> 11.0, >= 11.0.0) cucumber-cucumber-expressions (~> 15.1, >= 15.1.1) cucumber-gherkin (~> 23.0, >= 23.0.1) cucumber-html-formatter (~> 19.1, >= 19.1.0) cucumber-messages (~> 18.0, >= 18.0.0) diff-lcs (~> 1.5, >= 1.5.0) mime-types (~> 3.4, >= 3.4.1) multi_test (~> 1.1, >= 1.1.0) sys-uname (~> 1.2, >= 1.2.2) cucumber-ci-environment (9.1.0) cucumber-core (11.0.0) cucumber-gherkin (~> 23.0, >= 23.0.1) cucumber-messages (~> 18.0, >= 18.0.0) cucumber-tag-expressions (~> 4.1, >= 4.1.0) cucumber-cucumber-expressions (15.2.0) cucumber-gherkin (23.0.1) cucumber-messages (~> 18.0, >= 18.0.0) cucumber-html-formatter (19.2.0) cucumber-messages (~> 18.0, >= 18.0.0) cucumber-messages (18.0.0) cucumber-tag-expressions (4.1.0) diff-lcs (1.5.0) erubi (1.12.0) factory_bot (6.4.0) activesupport (>= 5.0.0) ffi (1.15.5) ffi (1.15.5-java) i18n (1.12.0) concurrent-ruby (~> 1.0) json (2.6.3) json (2.6.3-java) language_server-protocol (3.17.0.3) loofah (2.20.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) method_source (1.0.0) mime-types (3.4.1) mime-types-data (~> 3.2015) mime-types-data (3.2023.0218.1) mini_portile2 (2.8.1) minitest (5.18.0) multi_test (1.1.0) nokogiri (1.14.3) mini_portile2 (~> 2.8.0) racc (~> 1.4) nokogiri (1.14.3-java) racc (~> 1.4) parallel (1.23.0) parser (3.2.2.0) ast (~> 2.4.1) racc (1.6.2) racc (1.6.2-java) rack (2.2.6.4) rack-test (2.1.0) rack (>= 1.3) rails-dom-testing (2.0.3) activesupport (>= 4.2.0) nokogiri (>= 1.6) rails-html-sanitizer (1.5.0) loofah (~> 2.19, >= 2.19.1) railties (7.0.4.3) actionpack (= 7.0.4.3) activesupport (= 7.0.4.3) method_source rake (>= 12.2) thor (~> 1.0) zeitwerk (~> 2.5) rainbow (3.1.1) rake (13.0.6) regexp_parser (2.8.0) rexml (3.2.5) rspec-core (3.12.2) rspec-support (~> 3.12.0) rspec-expectations (3.12.3) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.12.0) rspec-mocks (3.12.5) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.12.0) rspec-rails (6.0.1) actionpack (>= 6.1) activesupport (>= 6.1) railties (>= 6.1) rspec-core (~> 3.11) rspec-expectations (~> 3.11) rspec-mocks (~> 3.11) rspec-support (~> 3.11) rspec-support (3.12.0) rubocop (1.50.2) json (~> 2.3) parallel (~> 1.10) parser (>= 3.2.0.0) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml (>= 3.2.5, < 4.0) rubocop-ast (>= 1.28.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 3.0) rubocop-ast (1.28.0) parser (>= 3.2.1.0) rubocop-performance (1.16.0) rubocop (>= 1.7.0, < 2.0) rubocop-ast (>= 0.4.0) ruby-progressbar (1.13.0) sqlite3 (1.6.2) mini_portile2 (~> 2.8.0) standard (1.27.0) language_server-protocol (~> 3.17.0.2) rubocop (~> 1.50.2) rubocop-performance (~> 1.16.0) sys-uname (1.2.3) ffi (~> 1.1) thor (1.2.1) tzinfo (2.0.6) concurrent-ruby (~> 1.0) unicode-display_width (2.4.2) zeitwerk (2.6.7) PLATFORMS java ruby DEPENDENCIES activerecord (>= 5.0.0) appraisal aruba cucumber factory_bot_rails! rake rspec-rails sqlite3 standard BUNDLED WITH 2.4.12 factory_bot_rails-6.4.2/LICENSE000066400000000000000000000020701452773104200162410ustar00rootroot00000000000000Copyright (c) 2008-2020 Joe Ferris and thoughtbot, inc. 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. factory_bot_rails-6.4.2/NEWS.md000066400000000000000000000074121452773104200163370ustar00rootroot00000000000000factory\_bot\_rails versioning is synced with factory\_bot releases. For this reason there might not be any notable changes in new versions of this project. # NEWS ## 6.4.2 (November 23, 2023) * Fixed: Fix Rails 7.1.2 + monkey-patched ActiveRecord compatibility (Adif Sgaid, Benoit Tigeot) * Internal: Test against Rails 7.1 (y-yagi) * Internal: Fix links to old files after renaming the main branch to `main` (y-yagi) ## 6.4.0 (November 17, 2023) * Releasing this for consistency with the factory\_bot dependency. ## 6.3.0 (November 17, 2023) * Changed: reject sequence definitions for ActiveRecord primary keys (Sean Doyle). * Changed: factory\_bot dependency to ~> 6.4 (Mike Burns). * Changed: upgrade dependencies (Daniel Colson). * Add: `projections.json` for Rails.vim (Caleb Hearth). * Docs: fix broken link (Edu Depetris). * Docs: mention Rails generator in docs (Edu Depetris). * Docs: fix typo (Yudai Takada). * Internal: skip Spring version 2.1.1 due to a bug in that release (Christina Entcheva, Daniel Colson). * Internal: test against Rails 6.1 (Antonis Berkakis). * Internal: test against Ruby 3 (Daniel Colson). * Internal: fewer warnings in Cucumber tests (Daniel Colson). * Internal: use GitHub Actions for CI (Mathieu Jobin). * Internal: a whole bunch of cleanup (Daniel Colson). * Internal: fix CI due to a Bundler output change (Mike Burns). ## 6.2.0 (May 7, 2021) * Changed: factory\_bot dependency to ~> 6.2.0 ## 6.1.0 (July 8, 2020) * Changed: factory\_bot dependency to ~> 6.1.0 ## 6.0.0 (June 18, 2020) * Fixed: generate a plural factory name when the --force-plural flag is provided * Changed: factory\_bot dependency to ~> 6.0.0 * Removed: `"factory_bot.register_reloader"` initializer, now registering the reloader after application initialization * Removed: support for EOL versions of Ruby (2.3, 2.4) and Rails (4.2) ## 5.2.0 (April 26, 2020) * Changed: factory\_bot dependency to ~> 5.2.0 ## 5.1.1 (September 24, 2019) * Fixed: Ensure definitions do not load before I18n is initialized ## 5.1.0 (September 24, 2019) * Changed: factory\_bot dependency to ~> 5.1.0 ## 5.0.2 (April 14, 2019) * Bugfix: Reload factory\_bot whenever the application changes to avoid holding onto stale object references * Bugfix: Avoid watching project root when no factory definitions exist ## 5.0.1 (February 9, 2019) * Bugfix: Avoid watching files and directories that don't exist (to avoid a file watching bug in Rails https://github.com/rails/rails/issues/32700) ## 5.0.0 (February 1, 2019) * Added: calling reload! in the Rails console will reload any factory definition files that have changed * Added: support for custom generator templates * Added: `definition_file_paths` configuration option, making it easier to place factories in custom locations * Changed: namespaced models are now generated inside a directory matching the namespace * Changed: added newline between factories generated into the same file * Removed: support for EOL version of Ruby and Rails ## 4.11.1 (September 7, 2018) * Update generator to use dynamic attributes instead of deprecated static attributes ## 4.11.0 (August 16, 2018) * No notable changes ## 4.10.0 (May 25, 2018) * No notable changes ## 4.8.2 (October 20, 2017) * Rename factory\_girl\_rails to factory\_bot\_rails ## 4.7.0 (April 1, 2016) * No notable changes ## 4.6.0 (February 1, 2016) * No notable changes ## 4.5.0 (October 17, 2014) * Improved README ## 4.4.1 (February 26, 2014) * Support Spring ## 4.2.1 (February 8, 2013) * Fix bug when configuring FG and RSpec fixture directory * Remove debugging * Require factory\_girl\_rails explicitly in generator ## 4.2.0 (January 25, 2013) * Add appraisal and get test suite working reliably with turn gem * Support MiniTest * Allow a custom directory for factories to be specified factory_bot_rails-6.4.2/README.md000066400000000000000000000147641452773104200165300ustar00rootroot00000000000000# factory_bot_rails [![Code Climate][grade-image]][grade] [![Gem Version][version-image]][version] [factory_bot][fb] is a fixtures replacement with a straightforward definition syntax, support for multiple build strategies (saved instances, unsaved instances, attribute hashes, and stubbed objects), and support for multiple factories for the same class (`user`, `admin_user`, and so on), including factory inheritance. ### Transitioning from factory\_girl\_rails? Check out the [guide](https://github.com/thoughtbot/factory_bot/blob/4-9-0-stable/UPGRADE_FROM_FACTORY_GIRL.md). ## Rails factory\_bot\_rails provides Rails integration for [factory_bot][fb]. Supported Rails versions are listed in [`Appraisals`](Appraisals). Supported Ruby versions are listed in [`.github/workflows/build.yml`](.github/workflows/build.yml). ## Download Github: http://github.com/thoughtbot/factory_bot_rails Gem: $ gem install factory_bot_rails ## Configuration Add `factory_bot_rails` to your Gemfile in both the test and development groups: ```ruby group :development, :test do gem 'factory_bot_rails' end ``` You may want to configure your test suite to include factory\_bot methods; see [configuration](https://github.com/thoughtbot/factory_bot/blob/master/GETTING_STARTED.md#configure-your-test-suite). ### Automatic Factory Definition Loading By default, factory\_bot\_rails will automatically load factories defined in the following locations, relative to the root of the Rails project: ``` factories.rb test/factories.rb spec/factories.rb factories/*.rb test/factories/*.rb spec/factories/*.rb ``` You can configure by adding the following to `config/application.rb` or the appropriate environment configuration in `config/environments`: ```ruby config.factory_bot.definition_file_paths = ["custom/factories"] ``` This will cause factory\_bot\_rails to automatically load factories in `custom/factories.rb` and `custom/factories/*.rb`. It is possible to use this setting to share factories from a gem: ```rb begin require 'factory_bot_rails' rescue LoadError end class MyEngine < ::Rails::Engine config.factory_bot.definition_file_paths += [File.expand_path('../factories', __FILE__)] if defined?(FactoryBotRails) end ``` You can also disable automatic factory definition loading entirely by using an empty array: ```rb config.factory_bot.definition_file_paths = [] ``` ### Generators Including factory\_bot\_rails in the development group of your Gemfile will cause Rails to generate factories instead of fixtures. If you want to disable this feature, you can either move factory\_bot\_rails out of the development group of your Gemfile, or add the following configuration: ```ruby config.generators do |g| g.factory_bot false end ``` If fixture replacement is enabled and you already have a `test/factories.rb` file (or `spec/factories.rb` if using rspec_rails), generated factories will be inserted at the top of the existing file. Otherwise, factories will be generated in the `test/factories` directory (`spec/factories` if using rspec_rails), in a file matching the name of the table (e.g. `test/factories/users.rb`). To generate factories in a different directory, you can use the following configuration: ```ruby config.generators do |g| g.factory_bot dir: 'custom/dir/for/factories' end ``` Note that factory\_bot\_rails will not automatically load files in custom locations unless you add them to `config.factory_bot.definition_file_paths` as well. The suffix option allows you to customize the name of the generated file with a suffix: ```ruby config.generators do |g| g.factory_bot suffix: "factory" end ``` This will generate `test/factories/users_factory.rb` instead of `test/factories/users.rb`. For even more customization, use the `filename_proc` option: ```ruby config.generators do |g| g.factory_bot filename_proc: ->(table_name) { "prefix_#{table_name}_suffix" } end ``` To override the [default factory template][], define your own template in `lib/templates/factory_bot/model/factories.erb`. This template will have access to any methods available in `FactoryBot::Generators::ModelGenerator`. Note that factory\_bot\_rails will only use this custom template if you are generating each factory in a separate file; it will have no effect if you are generating all of your factories in `test/factories.rb` or `spec/factories.rb`. Factory\_bot\_rails will add a custom generator: ```shell rails generate factory_bot:model NAME [field:type field:type] [options] ``` [default factory template]: https://github.com/thoughtbot/factory_bot_rails/tree/master/lib/generators/factory_bot/model/templates/factories.erb ### Active Record Configuration By default, FactoryBot will refuse to generate Active Record primary key columns. Without additional configuration, an Active Record model treats a column named `id` as its primary key. For example, defining an `id` attribute with `add_attribute(:id)`, `id { ... }`, or `sequence(:id)` will raise a `FactoryBot::AttributeDefinitionError`. You can disable this behavior by adding the following to `config/application.rb` or the appropriate environment configuration in `config/environments`: ```ruby config.factory_bot.reject_primary_key_attributes = false ``` ## Contributing Please see [CONTRIBUTING.md](CONTRIBUTING.md). factory_bot_rails was originally written by Joe Ferris and is maintained by thoughtbot. Many improvements and bugfixes were contributed by the [open source community](https://github.com/thoughtbot/factory_bot_rails/graphs/contributors). ## License factory_bot_rails is Copyright © 2008-2020 Joe Ferris and thoughtbot. It is free software, and may be redistributed under the terms specified in the [LICENSE](LICENSE) file. ## About thoughtbot ![thoughtbot](https://thoughtbot.com/brand_assets/93:44.svg) factory_bot_rails is maintained and funded by thoughtbot, inc. The names and logos for thoughtbot are trademarks of thoughtbot, inc. We are passionate about open source software. See [our other projects][community]. We are [available for hire][hire]. [fb]: https://github.com/thoughtbot/factory_bot [grade]: https://codeclimate.com/github/thoughtbot/factory_bot_rails [grade-image]: https://codeclimate.com/github/thoughtbot/factory_bot_rails.svg [community]: https://thoughtbot.com/community?utm_source=github [hire]: https://thoughtbot.com/hire-us?utm_source=github [version-image]: https://badge.fury.io/rb/factory_bot_rails.svg [version]: https://badge.fury.io/rb/factory_bot_rails [hound-image]: https://img.shields.io/badge/Reviewed_by-Hound-8E64B0.svg [hound]: https://houndci.com factory_bot_rails-6.4.2/RELEASING.md000066400000000000000000000017571452773104200171020ustar00rootroot00000000000000# Releasing 1. Update the version in the gemspec (and the factory\_bot version, if necessary) and run `bundle install` 1. Update `NEWS.md` to reflect the changes since last release. 1. Commit changes. There shouldn't be code changes, and thus CI doesn't need to run, so you can add "[ci skip]" to the commit message. 1. Tag the release: `git tag -s vVERSION` - We recommend the [_quick guide on how to sign a release_] from git ready. 1. Push changes: `git push && git push --tags` 1. Build and publish: ```bash gem build factory_bot_rails.gemspec gem push factory_bot_rails-VERSION.gem ``` 1. Add a new GitHub release using the recent `NEWS.md` as the content. Sample URL: https://github.com/thoughtbot/factory_bot_rails/releases/new?tag=vVERSION 1. Announce the new release, making sure to say "thank you" to the contributors who helped shape this version! [_quick guide on how to sign a release_]: http://gitready.com/advanced/2014/11/02/gpg-sign-releases.html factory_bot_rails-6.4.2/Rakefile000066400000000000000000000006441452773104200167060ustar00rootroot00000000000000require "bundler/setup" require "cucumber/rake/task" require "rspec/core/rake_task" require "standard/rake" Bundler::GemHelper.install_tasks name: "factory_bot_rails" Cucumber::Rake::Task.new(:cucumber) do |t| t.fork = true t.cucumber_opts = ["--format", (ENV["CUCUMBER_FORMAT"] || "progress")] end RSpec::Core::RakeTask.new(:spec) desc "Run the test suite and standard" task default: %w[spec cucumber standard] factory_bot_rails-6.4.2/bin/000077500000000000000000000000001452773104200160055ustar00rootroot00000000000000factory_bot_rails-6.4.2/bin/setup000077500000000000000000000005741452773104200171010ustar00rootroot00000000000000#!/usr/bin/env sh # Run this script immediately after cloning the codebase. # Exit if any subcommand fails set -e # Set up Ruby dependencies via Bundler bundle install # Add binstubs to PATH in ~/.zshenv like this: # export PATH=".git/safe/../../bin:$PATH" mkdir -p .git/safe # Set up Appraisal to help us test against multiple Rails versions bundle exec appraisal install factory_bot_rails-6.4.2/cucumber.yml000066400000000000000000000000311452773104200175570ustar00rootroot00000000000000default: --publish-quiet factory_bot_rails-6.4.2/factory_bot_rails.gemspec000066400000000000000000000014601452773104200223100ustar00rootroot00000000000000Gem::Specification.new do |s| s.name = "factory_bot_rails" s.version = "6.4.2" s.authors = ["Joe Ferris"] s.email = "jferris@thoughtbot.com" s.homepage = "https://github.com/thoughtbot/factory_bot_rails" s.summary = "factory_bot_rails provides integration between " \ "factory_bot and rails 5.0 or newer" s.description = "factory_bot_rails provides integration between " \ "factory_bot and rails 5.0 or newer" s.files = Dir["lib/**/*"] + %w[CONTRIBUTING.md LICENSE NEWS.md README.md] s.require_paths = ["lib"] s.executables = [] s.license = "MIT" s.add_runtime_dependency("factory_bot", "~> 6.4") s.add_runtime_dependency("railties", ">= 5.0.0") s.add_development_dependency("sqlite3") s.add_development_dependency("activerecord", ">= 5.0.0") end factory_bot_rails-6.4.2/features/000077500000000000000000000000001452773104200170535ustar00rootroot00000000000000factory_bot_rails-6.4.2/features/fixture_replacement_config.feature000066400000000000000000000134601452773104200260260ustar00rootroot00000000000000Feature: In order to not have to manually configure Factory Bot as the Rails testing fixture replacement by using the --fixture-replacement=factory_bot option I would like the Factory Bot Rails gem to configure Factory Bot as the fixture replacement. Background: Given I create a new rails application And I add "factory_bot_rails" from this project as a dependency Scenario: Using Factory Bot and Factory Bot Rails with Test Unit generates a factory file and does not generate a fixture file And I run `bundle install --verbose` with a clean environment And I run `bundle exec rails generate model User name:string` with a clean environment Then the following files should exist: | test/factories/users.rb | And the following files should not exist: | test/fixtures/users.yml | Scenario: Using Factory Bot and Factory Bot Rails with RSpec should generate a factory file When I add "rspec-rails" as a dependency And I configure the factories as: """ config.generators do |g| g.test_framework :rspec, fixture: true g.fixture_replacement :factory_bot end """ And I run `bundle install --verbose` with a clean environment Then the output should contain "rspec-rails" And I run `bundle exec rails generate model User name:string` with a clean environment Then the following files should exist: | spec/factories/users.rb | And the following files should not exist: | spec/fixtures/users.yml | Scenario: Using Factory Bot and Factory Bot Rails with RSpec and suffix configuration should generate a factory file with suffix When I add "rspec-rails" as a dependency And I configure the factories as: """ config.generators do |g| g.test_framework :rspec, fixture: true g.fixture_replacement :factory_bot, suffix: 'factory' end """ And I run `bundle install --verbose` with a clean environment Then the output should contain "rspec-rails" And I run `bundle exec rails generate model User name:string` with a clean environment Then the following files should exist: | spec/factories/users_factory.rb | And the following files should not exist: | spec/fixtures/users.yml | Scenario: Using Factory Bot and Factory Bot Rails does not override a manually-configured factories directory using RSpec When I add "rspec-rails" as a dependency And I configure the factories directory as "custom/dir" And I run `bundle install --verbose` with a clean environment Then the output should contain "rspec-rails" And I run `bundle exec rails generate model User name:string` with a clean environment Then the following files should not exist: | test/factories/users.rb | | spec/factories/users.rb | But the following files should exist: | custom/dir/users.rb | Scenario: Using Factory Bot and Factory Bot Rails does not override a manually-configured factories directory using Test::Unit When I configure the factories directory as "custom/dir" And I run `bundle install --verbose` with a clean environment And I run `bundle exec rails generate model User name:string` with a clean environment Then the following files should not exist: | test/factories/users.rb | | spec/factories/users.rb | But the following files should exist: | custom/dir/users.rb | Scenario: Using Factory Bot Rails with MiniTest should generate a factory file When I run `bundle install --verbose` with a clean environment And I run `bundle exec rails generate model User name:string` with a clean environment Then the following files should exist: | test/factories/users.rb | But the following files should not exist: | spec/fixtures/users.yml | Scenario: Using Factory Bot Rails with MiniTest and a custom directory should generate a factory file When I configure the factories directory as "custom/dir" And I run `bundle install --verbose` with a clean environment And I run `bundle exec rails generate model User name:string` with a clean environment Then the following files should exist: | custom/dir/users.rb | But the following files should not exist: | spec/fixtures/users.yml | Scenario: Disable Factory Bot generator When I configure the factories as: """ config.generators do |g| g.factory_bot false end """ And I run `bundle install --verbose` with a clean environment And I run `bundle exec rails generate model User name:string` with a clean environment Then the following files should not exist: | test/factories/users.rb | | spec/factories/users.rb | Scenario: Use a suffix with the Factory Bot generator When I add "rspec-rails" as a dependency When I configure the factories as: """ config.generators do |g| g.factory_bot suffix: 'suffix' end """ And I run `bundle install --verbose` with a clean environment And I run `bundle exec rails generate model User name:string` with a clean environment Then the following files should exist: | spec/factories/users_suffix.rb | Then the following files should not exist: | spec/factories/users.rb | Scenario: Use a filename_proc with the Factory Bot generator When I add "rspec-rails" as a dependency When I configure the factories as: """ config.generators do |g| g.factory_bot filename_proc: Proc.new { |tb| "prefix_#{tb.singularize}_suffix" } end """ And I run `bundle install --verbose` with a clean environment And I run `bundle exec rails generate model User name:string` with a clean environment Then the following files should exist: | spec/factories/prefix_user_suffix.rb | Then the following files should not exist: | spec/factories/users.rb | factory_bot_rails-6.4.2/features/generators.feature000066400000000000000000000070151452773104200226040ustar00rootroot00000000000000Feature: In order to easily generate factory files instead of fixture files when generating models As a user of Rails and Factory Bot I would like to use factory_bot_rails generators. Background: Given I create a new rails application And I add "factory_bot_rails" from this project as a dependency And I run `bundle install` with a clean environment Scenario: The factory_bot_rails generators create a factory file for each model if there is not a factories.rb file When I run `bundle exec rails generate model User name:string age:integer` with a clean environment And I run `bundle exec rails generate model Namespaced::User name:string` with a clean environment Then the output should contain "test/factories/users.rb" And the output should contain "test/factories/namespaced/users.rb" And the file "test/factories/users.rb" should contain exactly: """ FactoryBot.define do factory :user do name { "MyString" } age { 1 } end end """ And the file "test/factories/namespaced/users.rb" should contain "factory :namespaced_user, class: 'Namespaced::User' do" Scenario: The factory_bot_rails generators create a factory file with correct naming when I use --force-plural When I run `bundle exec rails generate model UserMedia filename:string --force-plural` with a clean environment Then the output should contain "test/factories/user_media.rb" And the file "test/factories/user_media.rb" should contain exactly: """ FactoryBot.define do factory :user_media do filename { "MyString" } end end """ Scenario: The factory_bot_rails generators add a factory in the correct spot When I write to "test/factories.rb" with: """ FactoryBot.define do end """ And I run `bundle exec rails generate model User name:string` with a clean environment And I run `bundle exec rails generate model Robot name:string` with a clean environment Then the file "test/factories.rb" should contain exactly: """ FactoryBot.define do factory :robot do name { "MyString" } end factory :user do name { "MyString" } end end """ Scenario: The factory_bot_rails generators does not create a factory file for each model if there is a factories.rb file in the test directory When I write to "test/factories.rb" with: """ FactoryBot.define do end """ And I run `bundle exec rails generate model User name:string` with a clean environment Then the file "test/factories/users.rb" should not contain "factory :user do" Scenario: The factory_bot_rails generators use a custom template When I write to "lib/templates/factory_bot/model/factories.erb" with: """ <%= "Custom factory definition" %> """ And I run `bundle exec rails generate model User` with a clean environment Then the file "test/factories/users.rb" should contain exactly: """ Custom factory definition """ Scenario: The factory_bot_rails generator can be disabled When I append to "config/application.rb" with: """ Rails.application.configure do config.generators do |g| g.factory_bot false end end """ And I run `bundle exec rails generate model User name:string age:integer` with a clean environment Then the output should not contain "test/factories/users.rb" And the output should contain "test/fixtures/users.yml" factory_bot_rails-6.4.2/features/load_definitions.feature000066400000000000000000000141621452773104200237460ustar00rootroot00000000000000Feature: automatically load factory definitions Background: When I create a new rails application And I add "factory_bot_rails" from this project as a dependency And I run `bundle install` with a clean environment And I write to "db/migrate/1_create_users.rb" with: """ migration_class = if ActiveRecord::Migration.respond_to?(:[]) ActiveRecord::Migration[4.2] else ActiveRecord::Migration end class CreateUsers < migration_class def self.up create_table :users do |t| t.string :name end end end """ When I run `bundle exec rake db:migrate` with a clean environment And I write to "app/models/user.rb" with: """ class User < ActiveRecord::Base end """ Scenario: generate a Rails application and use factory definitions When I write to "test/factories.rb" with: """ FactoryBot.define do factory :user do name { "Frank" } end end """ When I write to "test/unit/user_test.rb" with: """ require 'test_helper' class UserTest < ActiveSupport::TestCase test "use factory" do user = FactoryBot.create(:user) assert_equal 'Frank', user.name end end """ When I run `bundle exec rake test` with a clean environment Then the output should contain "1 assertions, 0 failures, 0 errors" Scenario: use custom definition file paths When I configure the factories as: """ config.factory_bot.definition_file_paths = ["custom_factories_path"] """ When I write to "custom_factories_path.rb" with: """ FactoryBot.define do factory :user do name { "Frank" } end end """ When I write to "test/unit/user_test.rb" with: """ require 'test_helper' class UserTest < ActiveSupport::TestCase test "use factory" do user = FactoryBot.create(:user) assert_equal 'Frank', user.name end end """ When I run `bundle exec rake test` with a clean environment Then the output should contain "1 assertions, 0 failures, 0 errors" Scenario: use 3rd-party factories with configured definition file paths When I append to "config/application.rb" with: """ require File.expand_path('../../lib/some_railtie/railties.rb', __FILE__) """ When I write to "lib/some_railtie/railties.rb" with: """ module SomeRailtie class Railtie < ::Rails::Engine config.factory_bot.definition_file_paths << File.expand_path('../factories', __FILE__) end end """ When I write to "lib/some_railtie/factories.rb" with: """ FactoryBot.define do factory :factory_from_some_railtie, class: 'User' do name { 'Artem' } end end """ When I write to "test/unit/user_test.rb" with: """ require 'test_helper' class UserTest < ActiveSupport::TestCase test "use factory of some_railtie" do user = FactoryBot.create(:factory_from_some_railtie) assert_equal 'Artem', user.name end end """ When I run `bundle exec rake test` with a clean environment Then the output should contain "1 assertions, 0 failures, 0 errors" Scenario: use 3rd-party factories with an initializer and without any user-defined factories When I append to "config/application.rb" with: """ require File.expand_path('../../lib/some_railtie/railties.rb', __FILE__) """ When I write to "lib/some_railtie/railties.rb" with: """ module SomeRailtie class Railtie < ::Rails::Engine initializer "some_railtie.factories", :after => "factory_bot.set_factory_paths" do FactoryBot.definition_file_paths << File.expand_path('../factories', __FILE__) end end end """ When I write to "lib/some_railtie/factories.rb" with: """ FactoryBot.define do factory :factory_from_some_railtie, class: 'User' do name { 'Artem' } end end """ When I write to "test/unit/user_test.rb" with: """ require 'test_helper' class UserTest < ActiveSupport::TestCase test "use factory of some_railtie" do railtie_user = FactoryBot.create(:factory_from_some_railtie) assert_equal 'Artem', railtie_user.name end end """ When I run `bundle exec rake test` with a clean environment Then the output should contain "1 assertions, 0 failures, 0 errors" Scenario: use 3rd-party factories with an initializer together with a user-defined factory When I append to "config/application.rb" with: """ require File.expand_path('../../lib/some_railtie/railties.rb', __FILE__) """ When I write to "lib/some_railtie/railties.rb" with: """ module SomeRailtie class Railtie < ::Rails::Engine initializer "some_railtie.factories", :after => "factory_bot.set_factory_paths" do FactoryBot.definition_file_paths << File.expand_path('../factories', __FILE__) end end end """ When I write to "lib/some_railtie/factories.rb" with: """ FactoryBot.define do factory :factory_from_some_railtie, class: 'User' do name { 'Artem' } end end """ When I write to "test/factories.rb" with: """ FactoryBot.define do factory :user do name { "Frank" } end end """ When I write to "test/unit/user_test.rb" with: """ require 'test_helper' class UserTest < ActiveSupport::TestCase test "use factory of some_railtie" do railtie_user = FactoryBot.create(:factory_from_some_railtie) assert_equal 'Artem', railtie_user.name user = FactoryBot.create(:user) assert_equal 'Frank', user.name end end """ When I run `bundle exec rake test` with a clean environment Then the output should contain "2 assertions, 0 failures, 0 errors" factory_bot_rails-6.4.2/features/reloading.feature000066400000000000000000000102421452773104200223730ustar00rootroot00000000000000Feature: automatically reloading factory_bot definitions Background: When I create a new rails application And I add "factory_bot_rails" from this project as a dependency And I run `bundle install` with a clean environment And I write to "db/migrate/1_create_users.rb" with: """ class CreateUsers < ActiveRecord::Migration[5.0] def self.up create_table :users do |t| t.string :name end end end """ And I run `bin/rails db:migrate` with a clean environment Scenario: When using factory_bot_rails together with Spring I want changes to my application to trigger the factory_bot_rails reloader So that factory_bot_rails doesn't hold onto stale class references When I write to "app/models/user.rb" with: """ class User < ActiveRecord::Base end """ And I write to "test/factories.rb" with: """ FactoryBot.define do factory :author, class: User do name { "Frank" } end end """ And I write to "test/unit/user_test.rb" with: """ require 'test_helper' class UserTest < ActiveSupport::TestCase test "user factory" do author = FactoryBot.create(:author) assert_equal author.class.object_id, User.object_id end end """ And I run `bundle binstubs bundler spring --force` with a clean environment And I run `bin/spring binstub --all` with a clean environment And I run `bin/rails test` with Spring enabled And I append to "app/models/user.rb" with: """ # User model edited """ And I run `bin/rails test` with Spring enabled And I run `bin/spring stop` with a clean environment #Then the output should contain "1 runs, 1 assertions" And the output should not contain "Failure:" Scenario: When using factory_bot_rails together with Spring I want changes to my factory_bot definitions to trigger a reload So that I can use my updated definitions without stopping spring When I write to "app/models/user.rb" with: """ class User < ActiveRecord::Base end """ And I write to "test/factories.rb" with: """ # Empty definition file to be picked up by the file watcher """ And I run `bundle binstubs bundler spring --force` with a clean environment And I run `bin/spring binstub --all` with a clean environment And I run `bin/rails test` with Spring enabled And I append to "test/factories.rb" with: """ FactoryBot.define do factory :author, class: User do name { "Frank" } end end """ And I write to "test/unit/user_test.rb" with: """ require 'test_helper' class UserTest < ActiveSupport::TestCase test "user factory" do author = FactoryBot.create(:author) assert_equal author.class.object_id, User.object_id end end """ And I run `bin/rails test` with Spring enabled And I run `bin/spring stop` with a clean environment #Then the output should contain "1 runs, 1 assertions" And the output should not contain "Failure:" Scenario: Initializing the reloader with I18n support When I write to "app/models/user.rb" with: """ class User TRANSLATION = I18n.translate("translation_key") end """ And I write to "config/locales/en.yml" with: """ en: translation_key: "translation_value" """ And I write to "test/factories.rb" with: """ FactoryBot.define do factory :user do User::TRANSLATION end end """ And I write to "test/unit/user_test.rb" with: """ require 'test_helper' class UserTest < ActiveSupport::TestCase test "user factory" do user = FactoryBot.build(:user) assert_equal "translation_value", User::TRANSLATION end end """ And I run `bin/rails test` with a clean environment Then the output should contain "1 runs, 1 assertions" And the output should not contain "Failure:" factory_bot_rails-6.4.2/features/step_definitions/000077500000000000000000000000001452773104200224215ustar00rootroot00000000000000factory_bot_rails-6.4.2/features/step_definitions/appraisal.rb000066400000000000000000000005621452773104200247250ustar00rootroot00000000000000When(/^I run `([^"]+)` with a clean environment$/) do |command| step <<~STEP I successfully run `ruby -e 'system({"BUNDLE_GEMFILE" => nil, "DISABLE_SPRING" => "true"}, "#{command}")'` STEP end When(/^I run `([^"]+)` with Spring enabled$/) do |command| step <<~STEP I successfully run `ruby -e 'system({"BUNDLE_GEMFILE" => nil}, "#{command}")'` STEP end factory_bot_rails-6.4.2/features/step_definitions/rails_steps.rb000066400000000000000000000031221452773104200252740ustar00rootroot00000000000000When(/^I create a new rails application$/) do options = %w[ --api --skip-bootsnap --skip-javascript --skip-action-mailer --skip-active-storage --skip-action-cable --skip-sprockets --skip-bundle ].join(" ") template = "-m ../../features/support/rails_template" result = run_command("bundle exec rails new test_app #{options} #{template}") expect(result).to have_output(/README/) expect(last_command_started).to be_successfully_executed cd("test_app") end When(/^I add "([^"]+)" from this project as a dependency$/) do |gem_name| append_to_file("Gemfile", %(gem "#{gem_name}", :path => "#{PROJECT_ROOT}"\n)) end When(/^I add "([^"]+)" as a dependency$/) do |gem_name| append_to_file("Gemfile", %(gem "#{gem_name}"\n)) end When(/^I print out "([^"]*)"$/) do |path| in_current_dir do File.open(path, "r") do |f| puts f.inspect end end end When(/^I configure the factories as:$/) do |string| append_to_file File.join("config", "application.rb"), <<~RUBY class TestApp::Application #{string} end RUBY end When(/^I configure the factories directory as "([^"]+)"$/) do |factory_dir| append_to_file File.join("config", "application.rb"), <<~RUBY class TestApp::Application config.generators do |g| g.fixture_replacement :factory_bot, :dir => "#{factory_dir}" end end RUBY end When(/^I comment out gem "([^"]*)" from my Gemfile$/) do |gem_name| in_current_dir do content = File.read("Gemfile") File.write("Gemfile", content.sub(/gem ['"]#{gem_name}/, '#\1')) end end factory_bot_rails-6.4.2/features/support/000077500000000000000000000000001452773104200205675ustar00rootroot00000000000000factory_bot_rails-6.4.2/features/support/env.rb000066400000000000000000000013321452773104200217030ustar00rootroot00000000000000require "aruba/cucumber" PROJECT_ROOT = File.expand_path(File.join(File.dirname(__FILE__), "..", "..")).freeze Aruba.configure do |config| config.exit_timeout = Integer ENV.fetch("ARUBA_TIMEOUT", 120) end if RUBY_PLATFORM == "java" Aruba.configure do |config| config.before_cmd do # disable JIT since these processes are so short lived set_env("JRUBY_OPTS", "-X-C #{ENV["JRUBY_OPTS"]}") java_options = ENV["JAVA_OPTS"] if 1.size == 4 # 4 for 32 bit java, 8 for 64 bit java. set_env("JAVA_OPTS", "-d32 #{java_options}") else set_env( "JAVA_OPTS", "-XX:+TieredCompilation -XX:TieredStopAtLevel=1 #{java_options}" ) end end end end factory_bot_rails-6.4.2/features/support/rails_template000066400000000000000000000002741452773104200235220ustar00rootroot00000000000000if Rails.gem_version < Gem::Version.new('6') gsub_file "Gemfile", /^gem 'sqlite3'$/, 'gem "sqlite3", "~> 1.3.6"' end gsub_file "Gemfile", /^ gem 'spring'$/, ' gem "spring", "!= 2.1.1"' factory_bot_rails-6.4.2/gemfiles/000077500000000000000000000000001452773104200170305ustar00rootroot00000000000000factory_bot_rails-6.4.2/gemfiles/rails5.0.gemfile000066400000000000000000000006121452773104200217160ustar00rootroot00000000000000# This file was generated by Appraisal source "https://rubygems.org" gem "appraisal" gem "aruba" gem "cucumber" gem "rake" gem "rspec-rails" gem "standard" gem "byebug" gem "listen", "~> 3.0.5" gem "puma", "~> 3.0" gem "rails", "~> 5.0.7", ">= 5.0.7.2" gem "spring", "!= 2.1.1" gem "spring-watcher-listen", "~> 2.0.0" gem "sqlite3", "~> 1.3.6" gemspec name: "factory_bot_rails", path: "../" factory_bot_rails-6.4.2/gemfiles/rails5.1.gemfile000066400000000000000000000006051452773104200217210ustar00rootroot00000000000000# This file was generated by Appraisal source "https://rubygems.org" gem "appraisal" gem "aruba" gem "cucumber" gem "rake" gem "rspec-rails" gem "standard" gem "byebug" gem "listen", ">= 3.0.5", "< 3.2" gem "puma", "~> 3.7" gem "rails", "~> 5.1.7" gem "spring", "!= 2.1.1" gem "spring-watcher-listen", "~> 2.0.0" gem "sqlite3", "~> 1.3.6" gemspec name: "factory_bot_rails", path: "../" factory_bot_rails-6.4.2/gemfiles/rails5.2.gemfile000066400000000000000000000006241452773104200217230ustar00rootroot00000000000000# This file was generated by Appraisal source "https://rubygems.org" gem "appraisal" gem "aruba" gem "cucumber" gem "rake" gem "rspec-rails" gem "standard" gem "byebug" gem "listen", ">= 3.0.5", "< 3.2" gem "puma", "~> 3.11" gem "rails", "~> 5.2.4", ">= 5.2.4.2" gem "spring", "!= 2.1.1" gem "spring-watcher-listen", "~> 2.0.0" gem "sqlite3", "~> 1.3.6" gemspec name: "factory_bot_rails", path: "../" factory_bot_rails-6.4.2/gemfiles/rails6.0.gemfile000066400000000000000000000006061452773104200217220ustar00rootroot00000000000000# This file was generated by Appraisal source "https://rubygems.org" gem "appraisal" gem "aruba" gem "cucumber" gem "rake" gem "rspec-rails" gem "standard" gem "byebug" gem "listen", "~> 3.2" gem "puma", "~> 4.1" gem "rails", "~> 6.0.2", ">= 6.0.2.2" gem "spring", "!= 2.1.1" gem "spring-watcher-listen", "~> 2.0.0" gem "sqlite3", "~> 1.4" gemspec name: "factory_bot_rails", path: "../" factory_bot_rails-6.4.2/gemfiles/rails6.1.gemfile000066400000000000000000000006061452773104200217230ustar00rootroot00000000000000# This file was generated by Appraisal source "https://rubygems.org" gem "appraisal" gem "aruba" gem "cucumber" gem "rake" gem "rspec-rails" gem "standard" gem "byebug" gem "listen", "~> 3.2" gem "puma", "~> 5.0" gem "rails", "~> 6.1.0", ">= 6.1.0.0" gem "spring", "!= 2.1.1" gem "spring-watcher-listen", "~> 2.0.0" gem "sqlite3", "~> 1.4" gemspec name: "factory_bot_rails", path: "../" factory_bot_rails-6.4.2/gemfiles/rails7.0.gemfile000066400000000000000000000006041452773104200217210ustar00rootroot00000000000000# This file was generated by Appraisal source "https://rubygems.org" gem "appraisal" gem "aruba" gem "cucumber" gem "rake" gem "rspec-rails" gem "standard" gem "byebug" gem "listen", "~> 3.2" gem "puma", "~> 5.0" gem "rails", "~> 7.0.1", ">= 7.0.1" gem "spring", "!= 2.1.1" gem "spring-watcher-listen", "~> 2.0.0" gem "sqlite3", "~> 1.4" gemspec name: "factory_bot_rails", path: "../" factory_bot_rails-6.4.2/lib/000077500000000000000000000000001452773104200160035ustar00rootroot00000000000000factory_bot_rails-6.4.2/lib/factory_bot_rails.rb000066400000000000000000000001001452773104200220240ustar00rootroot00000000000000require "factory_bot_rails/railtie" module FactoryBotRails end factory_bot_rails-6.4.2/lib/factory_bot_rails/000077500000000000000000000000001452773104200215105ustar00rootroot00000000000000factory_bot_rails-6.4.2/lib/factory_bot_rails/definition_file_paths.rb000066400000000000000000000010131452773104200263560ustar00rootroot00000000000000# frozen_string_literal: true module FactoryBotRails class DefinitionFilePaths def initialize(definition_file_paths) @files = [] @directories = {} definition_file_paths.each do |path| @files << "#{path}.rb" @directories[path.to_s] = [:rb] end end def directories @directories.select { |path| Dir.exist?(path) } end def files @files.select { |file| File.exist?(file) } end def any? directories.any? || files.any? end end end factory_bot_rails-6.4.2/lib/factory_bot_rails/factory_validator.rb000066400000000000000000000015331452773104200255530ustar00rootroot00000000000000module FactoryBotRails class FactoryValidator def initialize(validators = []) @validators = Array(validators) end def add_validator(validator) @validators << validator end def run ActiveSupport::Notifications.subscribe("factory_bot.compile_factory", &validate_compiled_factory) end private def validate_compiled_factory if Rails.version >= "6.0" rails_6_0_support else rails_5_2_support end end def rails_6_0_support proc do |event| @validators.each { |validator| validator.validate!(event.payload) } end end def rails_5_2_support proc do |*notification_event_arguments| event = ActiveSupport::Notifications::Event.new(*notification_event_arguments) rails_6_0_support.call(event) end end end end factory_bot_rails-6.4.2/lib/factory_bot_rails/factory_validator/000077500000000000000000000000001452773104200252245ustar00rootroot00000000000000factory_bot_rails-6.4.2/lib/factory_bot_rails/factory_validator/active_record_validator.rb000066400000000000000000000012231452773104200324250ustar00rootroot00000000000000module FactoryBotRails class FactoryValidator class ActiveRecordValidator def validate!(payload) attributes, for_class = payload.values_at(:attributes, :class) attributes.each do |attribute| if for_class < ActiveRecord::Base && for_class.primary_key == attribute.name.to_s raise FactoryBot::AttributeDefinitionError, <<~ERROR Attribute generates #{for_class.primary_key.inspect} primary key for #{for_class.name}" Do not define #{for_class.primary_key.inspect}. Instead, rely on the database to generate it. ERROR end end end end end end factory_bot_rails-6.4.2/lib/factory_bot_rails/generator.rb000066400000000000000000000014271452773104200240270ustar00rootroot00000000000000require "factory_bot_rails/generators/rspec_generator" require "factory_bot_rails/generators/non_rspec_generator" require "factory_bot_rails/generators/null_generator" module FactoryBotRails class Generator def initialize(config) @generators = config.app_generators end def run generator.new(@generators).run end def generator return Generators::NullGenerator if factory_bot_disabled? if test_framework == :rspec Generators::RSpecGenerator else Generators::NonRSpecGenerator end end def test_framework rails_options[:test_framework] end def factory_bot_disabled? rails_options[:factory_bot] == false end def rails_options @generators.options[:rails] end end end factory_bot_rails-6.4.2/lib/factory_bot_rails/generators/000077500000000000000000000000001452773104200236615ustar00rootroot00000000000000factory_bot_rails-6.4.2/lib/factory_bot_rails/generators/non_rspec_generator.rb000066400000000000000000000006641452773104200302500ustar00rootroot00000000000000module FactoryBotRails module Generators class NonRSpecGenerator def initialize(generators) @generators = generators end def run @generators.test_framework( test_framework, fixture: false, fixture_replacement: :factory_bot ) end private def test_framework @generators.options[:rails][:test_framework] end end end end factory_bot_rails-6.4.2/lib/factory_bot_rails/generators/null_generator.rb000066400000000000000000000002201452773104200272200ustar00rootroot00000000000000module FactoryBotRails module Generators class NullGenerator def initialize(*) end def run end end end end factory_bot_rails-6.4.2/lib/factory_bot_rails/generators/rspec_generator.rb000066400000000000000000000012061452773104200273670ustar00rootroot00000000000000module FactoryBotRails module Generators class RSpecGenerator def initialize(generators) @generators = generators end def run @generators.fixture_replacement( fixture_replacement_setting, dir: factory_bot_directory ) end private def fixture_replacement_setting @generators.options[:rails][:fixture_replacement] || :factory_bot end def factory_bot_directory factory_bot_options.fetch(:dir, "spec/factories") end def factory_bot_options @generators.options.fetch(:factory_bot, {}) end end end end factory_bot_rails-6.4.2/lib/factory_bot_rails/railtie.rb000066400000000000000000000025351452773104200234730ustar00rootroot00000000000000# frozen_string_literal: true require "factory_bot" require "factory_bot_rails/generator" require "factory_bot_rails/reloader" require "factory_bot_rails/factory_validator" require "rails" module FactoryBotRails class Railtie < Rails::Railtie config.factory_bot = ActiveSupport::OrderedOptions.new config.factory_bot.definition_file_paths = FactoryBot.definition_file_paths config.factory_bot.reject_primary_key_attributes = true config.factory_bot.validator = FactoryBotRails::FactoryValidator.new initializer "factory_bot.set_fixture_replacement" do Generator.new(config).run end initializer "factory_bot.set_factory_paths" do FactoryBot.definition_file_paths = definition_file_paths end ActiveSupport.on_load :active_record do config = Rails.configuration.factory_bot if config.reject_primary_key_attributes require "factory_bot_rails/factory_validator/active_record_validator" config.validator.add_validator FactoryValidator::ActiveRecordValidator.new end end config.after_initialize do |app| FactoryBot.find_definitions Reloader.new(app).run app.config.factory_bot.validator.run end private def definition_file_paths config.factory_bot.definition_file_paths.map do |path| Rails.root.join(path) end end end end factory_bot_rails-6.4.2/lib/factory_bot_rails/reloader.rb000066400000000000000000000013211452773104200236270ustar00rootroot00000000000000# frozen_string_literal: true require "factory_bot_rails/definition_file_paths" module FactoryBotRails class Reloader def initialize(app) @app = app @paths = DefinitionFilePaths.new(FactoryBot.definition_file_paths) end def run return unless @paths.any? register_reloader(build_reloader) end private attr_reader :app def build_reloader reloader_class.new(@paths.files, @paths.directories) do FactoryBot.reload end end def reloader_class app.config.file_watcher end def register_reloader(reloader) app.reloader.to_prepare do reloader.execute end app.reloaders << reloader end end end factory_bot_rails-6.4.2/lib/generators/000077500000000000000000000000001452773104200201545ustar00rootroot00000000000000factory_bot_rails-6.4.2/lib/generators/factory_bot.rb000066400000000000000000000011011452773104200230050ustar00rootroot00000000000000require "rails/generators/named_base" module FactoryBot module Generators class Base < Rails::Generators::NamedBase # :nodoc: def self.source_root path = File.join( File.dirname(__FILE__), "factory_bot", generator_name, "templates" ) File.expand_path(path) end def factory_name class_name.gsub("::", "").underscore end def explicit_class_option return if class_name.underscore == factory_name ", class: '#{class_name}'" end end end end factory_bot_rails-6.4.2/lib/generators/factory_bot/000077500000000000000000000000001452773104200224675ustar00rootroot00000000000000factory_bot_rails-6.4.2/lib/generators/factory_bot/model/000077500000000000000000000000001452773104200235675ustar00rootroot00000000000000factory_bot_rails-6.4.2/lib/generators/factory_bot/model/model_generator.rb000066400000000000000000000040321452773104200272610ustar00rootroot00000000000000require "generators/factory_bot" require "factory_bot_rails" module FactoryBot module Generators class ModelGenerator < Base argument( :attributes, type: :array, default: [], banner: "field:type field:type" ) class_option( :dir, type: :string, default: "test/factories", desc: "The directory or file root where factories belong" ) class_option( :suffix, type: :string, default: nil, desc: "Suffix to add factory file" ) def create_fixture_file if File.exist?(factories_file) insert_factory_into_existing_file else create_factory_file end end private def factories_file options[:dir] + ".rb" end def insert_factory_into_existing_file insert_into_file( factories_file, factory_definition, after: "FactoryBot.define do\n" ) end def create_factory_file file = File.join(options[:dir], "#{filename}.rb") template "factories.erb", file end def factory_definition <<~RUBY factory :#{factory_name}#{explicit_class_option} do #{factory_attributes.gsub(/^/, " ")} end RUBY end def factory_attributes attributes.map { |attribute| "#{attribute.name} { #{attribute.default.inspect} }" }.join("\n") end def filename if factory_bot_options[:filename_proc].present? factory_bot_options[:filename_proc].call(table_name) else name = File.join(class_path, plural_name) [name, filename_suffix].compact.join("_") end end def filename_suffix factory_bot_options[:suffix] || options[:suffix] end def factory_bot_options generators.options[:factory_bot] || {} end def generators FactoryBotRails::Railtie.config.app_generators end end end end factory_bot_rails-6.4.2/lib/generators/factory_bot/model/templates/000077500000000000000000000000001452773104200255655ustar00rootroot00000000000000factory_bot_rails-6.4.2/lib/generators/factory_bot/model/templates/factories.erb000066400000000000000000000000721452773104200302350ustar00rootroot00000000000000FactoryBot.define do <%= factory_definition.rstrip %> end factory_bot_rails-6.4.2/lib/rails/000077500000000000000000000000001452773104200171155ustar00rootroot00000000000000factory_bot_rails-6.4.2/lib/rails/projections.json000066400000000000000000000011111452773104200223410ustar00rootroot00000000000000{ "spec/factories/*.rb": { "alternate": "app/models/{singular}.rb", "collection": "model", "command": "factory", "template": [ "FactoryBot.define do", " factory :{singular} do", " end", "end" ], "test": "spec/models/{singular}_spec.rb" }, "test/factories/*.rb": { "alternate": "app/models/{singular}.rb", "collection": "model", "command": "factory", "template": [ "FactoryBot.define do", " factory :{singular} do", " end", "end" ], "test": "test/models/{singular}_test.rb" } } factory_bot_rails-6.4.2/spec/000077500000000000000000000000001452773104200161675ustar00rootroot00000000000000factory_bot_rails-6.4.2/spec/factory_bot_rails/000077500000000000000000000000001452773104200216745ustar00rootroot00000000000000factory_bot_rails-6.4.2/spec/factory_bot_rails/definition_file_paths_spec.rb000066400000000000000000000025661452773104200275720ustar00rootroot00000000000000# frozen_string_literal: true describe FactoryBotRails::DefinitionFilePaths do describe "#files" do it "returns a list of definition files that only exist" do definition_file_paths = ["spec/fixtures/factories", "not_exist_directory"] files = described_class.new(definition_file_paths).files expect(files).to eq ["spec/fixtures/factories.rb"] end end describe "#directories" do it "returns a hash of definition directories that only exist" do definition_file_paths = ["spec/fixtures/factories", "not_exist_directory"] directories = described_class.new(definition_file_paths).directories expect(directories).to eq( "spec/fixtures/factories" => [:rb] ) end it "converts Pathname objects to strings" do definition_file_paths = [Pathname.new("spec/fixtures/factories")] directories = described_class.new(definition_file_paths).directories expect(directories).to eq("spec/fixtures/factories" => [:rb]) end end describe "#any?" do it "returns true only if definition file paths exist" do definition_file_paths = ["spec/fixtures/factories", "not_exist_directory"] expect(described_class.new(definition_file_paths).any?).to eq true definition_file_paths = ["not_exist_directory"] expect(described_class.new(definition_file_paths).any?).to eq false end end end factory_bot_rails-6.4.2/spec/factory_bot_rails/factory_validator/000077500000000000000000000000001452773104200254105ustar00rootroot00000000000000factory_bot_rails-6.4.2/spec/factory_bot_rails/factory_validator/active_record_validator_spec.rb000066400000000000000000000012161452773104200336250ustar00rootroot00000000000000# frozen_string_literal: true describe FactoryBotRails::FactoryValidator do before { FactoryBot.reload } describe "ActiveRecordValidator" do context "when defined with a class that descends from ActiveRecord::Base" do it "raises an error for a sequence generating its primary key" do define_model "Article", an_id: :integer do self.primary_key = :an_id end FactoryBot.define do factory :article do sequence(:an_id) end end expect { FactoryBot.create(:article) } .to raise_error(FactoryBot::AttributeDefinitionError) end end end end factory_bot_rails-6.4.2/spec/factory_bot_rails/railtie_spec.rb000066400000000000000000000023261452773104200246670ustar00rootroot00000000000000# frozen_string_literal: true describe FactoryBotRails::Railtie do describe "application reloading" do context "when a definition file has been updated" do it "reloads the factory definitions" do allow(FactoryBot).to receive(:reload) touch("factories.rb") reload_rails! expect(FactoryBot).to have_received(:reload).at_least(1).times end end context "when a file in a definition directory has been updated" do it "reloads the factory definitions" do allow(FactoryBot).to receive(:reload) touch("factories/definitions.rb") reload_rails! expect(FactoryBot).to have_received(:reload).at_least(1).times end end context "when the factory definitions have NOT been updated" do it "reloads the factory definitions" do allow(FactoryBot).to receive(:reload) reload_rails! expect(FactoryBot).to have_received(:reload).at_least(1).times end end def touch(file) FileUtils.touch(Rails.root.join(file)) end def reload_rails! Rails.application.reloader.reload! wait_for_rails_to_reload end def wait_for_rails_to_reload sleep 0.01 end end end factory_bot_rails-6.4.2/spec/factory_bot_rails/reloader_spec.rb000066400000000000000000000040141452773104200250270ustar00rootroot00000000000000# frozen_string_literal: true describe FactoryBotRails::Reloader do describe "#run" do before do @original_definition_file_paths = FactoryBot.definition_file_paths end after do FactoryBot.definition_file_paths = @original_definition_file_paths end context "when a definition file paths exist" do it "registers a reloader" do file_watcher = file_watcher_double run_reloader( ["spec/fixtures/factories", "not_exist_directory"], file_watcher ) expect(file_watcher).to have_received(:new) end end context "when a file exists but not a directory" do it "registers a reloader" do file_watcher = file_watcher_double run_reloader( ["spec/fake_app", "not_exist_directory"], file_watcher ) expect(file_watcher).to have_received(:new) end end context "when a definition file paths NOT exist" do it "does NOT register a reloader" do file_watcher = file_watcher_double run_reloader(["not_exist_directory"], file_watcher) expect(file_watcher).not_to have_received(:new) end end def run_reloader(definition_file_paths, file_watcher) FactoryBot.definition_file_paths = definition_file_paths app = app_double(file_watcher) FactoryBotRails::Reloader.new(app).run end def file_watcher_double class_double( Rails.application.config.file_watcher, new: double(:reloader, execute: nil) ) end def app_double(file_watcher) instance_double( Rails.application.class, config: app_config_double(file_watcher), reloader: reloader_double, reloaders: [] ) end def app_config_double(file_watcher) instance_double( Rails.application.config.class, file_watcher: file_watcher ) end def reloader_double class_double( Rails.application.reloader, to_prepare: nil ) end end end factory_bot_rails-6.4.2/spec/fake_app.rb000066400000000000000000000003461452773104200202650ustar00rootroot00000000000000# frozen_string_literal: true module Dummy class Application < Rails::Application config.eager_load = false config.root = "spec/fixtures" end end Rails.logger = Logger.new("/dev/null") Rails.application.initialize! factory_bot_rails-6.4.2/spec/fixtures/000077500000000000000000000000001452773104200200405ustar00rootroot00000000000000factory_bot_rails-6.4.2/spec/fixtures/factories.rb000066400000000000000000000000421452773104200223400ustar00rootroot00000000000000# Rails.root.join('factories.rb') factory_bot_rails-6.4.2/spec/fixtures/factories/000077500000000000000000000000001452773104200220175ustar00rootroot00000000000000factory_bot_rails-6.4.2/spec/fixtures/factories/definitions.rb000066400000000000000000000000611452773104200246540ustar00rootroot00000000000000# Rails.root.join('factories', 'definitions.rb') factory_bot_rails-6.4.2/spec/spec_helper.rb000066400000000000000000000004661452773104200210130ustar00rootroot00000000000000# frozen_string_literal: true ENV["RAILS_ENV"] = "test" require "factory_bot_rails" require "fake_app" Dir["spec/support/**/*.rb"].each { |f| require File.expand_path(f) } RSpec.configure do |config| config.run_all_when_everything_filtered = true config.filter_run :focus config.order = "random" end factory_bot_rails-6.4.2/spec/support/000077500000000000000000000000001452773104200177035ustar00rootroot00000000000000factory_bot_rails-6.4.2/spec/support/macros/000077500000000000000000000000001452773104200211675ustar00rootroot00000000000000factory_bot_rails-6.4.2/spec/support/macros/define_constant.rb000066400000000000000000000027431452773104200246650ustar00rootroot00000000000000require "active_record" module DefineConstantMacros def define_class(path, base = Object, &block) const = stub_const(path, Class.new(base)) const.class_eval(&block) if block const end def define_model(name, columns = {}, &block) model = define_class(name, ActiveRecord::Base, &block) create_table(model.table_name) do |table| columns.each do |column_name, type| table.column column_name, type end end model end def create_table(table_name, &block) connection = ActiveRecord::Base.connection begin connection.execute("DROP TABLE IF EXISTS #{table_name}") connection.create_table(table_name, &block) created_tables << table_name connection rescue Exception => e # rubocop:disable Lint/RescueException connection.execute("DROP TABLE IF EXISTS #{table_name}") raise e end end def clear_generated_tables created_tables.each do |table_name| clear_generated_table(table_name) end created_tables.clear end def clear_generated_table(table_name) ActiveRecord::Base .connection .execute("DROP TABLE IF EXISTS #{table_name}") end private def created_tables @created_tables ||= [] end end RSpec.configure do |config| config.include DefineConstantMacros config.before(:all) do ActiveRecord::Base.establish_connection( adapter: "sqlite3", database: ":memory:" ) end config.after do clear_generated_tables end end