diff --git a/CHANGELOG.md b/CHANGELOG.md index 077d767a..68efc824 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Master (Unreleased) +- Fix a false positive for `FactoryBot/AssociationStyle` when using nested factories with traits. ([@jaydorsey]) + ## 2.25.1 (2024-01-08) - Fix a false positive for `FactoryBot/CreateList` when create call does have method calls and repeat multiple times with other argument. ([@ydah]) @@ -88,6 +90,7 @@ [@ddieulivol]: https://github.com/ddieulivol [@dmitrytsepelev]: https://github.com/dmitrytsepelev [@harrylewis]: https://github.com/harrylewis +[@jaydorsey]: https://github.com/jaydorsey [@jfragoulis]: https://github.com/jfragoulis [@jonatas]: https://github.com/jonatas [@leoarnold]: https://github.com/leoarnold diff --git a/lib/rubocop/cop/factory_bot/association_style.rb b/lib/rubocop/cop/factory_bot/association_style.rb index 7a483e5a..4a08f46d 100644 --- a/lib/rubocop/cop/factory_bot/association_style.rb +++ b/lib/rubocop/cop/factory_bot/association_style.rb @@ -67,6 +67,7 @@ class AssociationStyle < ::RuboCop::Cop::Base # rubocop:disable Metrics/ClassLen DEFAULT_NON_IMPLICIT_ASSOCIATION_METHOD_NAMES = %w[ association + factory sequence skip_create traits_for_enum diff --git a/spec/rubocop/cop/factory_bot/association_style_spec.rb b/spec/rubocop/cop/factory_bot/association_style_spec.rb index 01afc883..874cfbd3 100644 --- a/spec/rubocop/cop/factory_bot/association_style_spec.rb +++ b/spec/rubocop/cop/factory_bot/association_style_spec.rb @@ -405,5 +405,19 @@ def inspected_source_filename RUBY end end + + context 'when factory inside a factory with inline traits' do + it 'does not register an offense' do + expect_no_offenses(<<~RUBY) + factory :order do + traits :completed do + completed_at { 3.days.ago } + end + + factory :order_completed, traits: [:completed] + end + RUBY + end + end end end