Factory bot 5.2.0 use parent strategy false - #51338
Closed
Hamms wants to merge 12 commits into
Closed
Conversation
Specifically target the latest 5.x version as a transitional step toward v6.2, which adds support for Ruby 3. Breaking changes in v5: - Removed support for EOL versions of Ruby and Rails - Removed static attributes (use dynamic attributes with a block instead) - Removed looking up factories by class - Removed ignore method (use transient instead) - Removed duplicate_attribute_assignment_from_initialize_with configuration option https://github.com/thoughtbot/factory_bot/releases/tag/v5.0.0
In preparation for an update to FactoryBot 5.x (and beyond), which deprecated static attributes in favor of dynamic attributes. Update Update applied automatically by temporarily configuring my local environment to enable the `FactoryBot/AttributeDefinedStatically` lint rule: ```diff diff --git a/.rubocop.yml b/.rubocop.yml index 041a14a..594b15160a3 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -6,6 +6,7 @@ inherit_from: require: - rubocop-performance - rubocop-rails + - rubocop-rspec - rubocop-rails-accessibility - './tools/customLinters/rubocop_only_allowed_characters.rb' @@ -74,6 +75,10 @@ Style/Semicolon: Style/WordArray: MinSize: 5 +RSpec/FactoryBot/AttributeDefinedStatically: + Include: + - 'dashboard/test/factories/*.rb' + # END CODE.ORG OVERRIDES # BEGIN BLOCKLIST: Below are rules we don't plan to enable in the forseeable diff --git a/Gemfile b/Gemfile index 81ed267..917649bcb73 100644 --- a/Gemfile +++ b/Gemfile @@ -242,6 +242,7 @@ group :development, :staging, :levelbuilder do gem 'rubocop-performance', require: false gem 'rubocop-rails', require: false gem 'rubocop-rails-accessibility', require: false + gem 'rubocop-rspec', require: false gem 'scss_lint', require: false end ``` And then running `rubocop --require rubocop-rspec --only RSpec/FactoryBot/AttributeDefinedStatically --auto-correct dashboard/test/factories/*`. I then used `rubocop --only Layout/SpaceInsideBlockBraces --auto-correct dashboard/test/factories/*.rb` to automatically fix some white space errors, and manually edited `dashboard/test/factories/foorm_factories.rb` to fix up a few more. - https://thoughtbot.com/blog/deprecating-static-attributes-in-factory_bot-4-11 - https://docs.rubocop.org/rubocop-rspec/cops_rspec_factorybot.html#rspecfactorybotattributedefinedstatically
In preparation for an update to FactoryBot 5, which fixes some unintuitive behavior when `build`ing objects with descendents. Specifically, the `:pd_teacher_application` factory calls `build :pd_teacher_application_hash_common` which in turn calls `association :school`; right now, even though the Hash is being called with `build` rather than `create`, that `School` object still gets persisted. In fact, that behavior is *required* since we pass the `id` of the `School` object upstream to the `:pd_teacher_application` factory which as part of its own persistence logic expects its `school_id` attribute to reference a persisted object. Startingin FactoryBot 5, the default association strategy will now be inherited from the parent factory, so `build`ing a hash will `build` but not persist the associated `School` object. In most cases this is probably desirable, but here we are relying on the old strange behavior and so now need to explicitly specify that we always want to persist the associated `School` object. https://github.com/thoughtbot/factory_bot/blob/main/GETTING_STARTED.md#build-strategies-1
…ry_bot-5.2.0-use_parent_strategy-false
Contributor
Author
|
closing in favor of #50912 |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Warning!!
The AP CSP Create Performance Task is in progress from April 1 - May 1 2023. Please
consider any risk introduced by this PR that could affect our students taking AP CSP. Code.org
students taking AP CSP primarily use App Lab for their Create Task, however a small percent use Game
Lab. Carefully consider whether your change has any risk of alterering, changing, or breaking
anything in these two labs. Even small changes, such as a different button color, are considered
significant during this time period. Reach out to the Student Learning team or Curriculum team for
more details.
Links
Testing story
Deployment strategy
Follow-up work
Privacy
Security
Caching
PR Checklist: