Skip to content

Commit

Permalink
FactoryBot/AssociationStyle nested factories
Browse files Browse the repository at this point in the history
  • Loading branch information
jaydorsey committed Apr 24, 2024
1 parent 8dc44b0 commit c00250c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Master (Unreleased)

- Fix a false positive for `FactoryBot/AssociationStyle` when using nested factories ([@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])
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/factory_bot/association_style.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions spec/rubocop/cop/factory_bot/association_style_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,20 @@ def inspected_source_filename
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

context 'when use an association with the same name as trait' do
it 'registers and corrects an offense' do
expect_offense(<<~RUBY)
Expand Down

0 comments on commit c00250c

Please sign in to comment.