Update FactoryBot Static Attributes to Dynamic - #51336
Merged
Merged
Conversation
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
Hamms
marked this pull request as ready for review
April 14, 2023 18:04
cat5inthecradle
approved these changes
Apr 14, 2023
cat5inthecradle
left a comment
Contributor
There was a problem hiding this comment.
LGTM - I trust the process on this being valid. Looks good scanning through it, though I've admittedly never used FactoryBot.
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.
In preparation for an update to FactoryBot 5.x (and beyond), which deprecated static attributes in favor of dynamic attributes
Update applied automatically by temporarily configuring my local environment to enable the
FactoryBot/AttributeDefinedStaticallylint rule:And then running:
I then used
rubocop --only Layout/SpaceInsideBlockBraces --auto-correct dashboard/test/factories/*.rbto automatically fix some white space errors, and manually editeddashboard/test/factories/foorm_factories.rbto fix up a few more.Links
Testing story
Relying on our existing tests to verify that this update to test configuration syntax does not result in any functional changes.
Follow-up work
After this, we should be ready to upgrade to FactoryBot 5.x