Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FactoryBot/AssociationStyle error on nested factories #113

Closed
jaydorsey opened this issue Apr 24, 2024 · 1 comment · Fixed by #114
Closed

FactoryBot/AssociationStyle error on nested factories #113

jaydorsey opened this issue Apr 24, 2024 · 1 comment · Fixed by #114

Comments

@jaydorsey
Copy link
Contributor

I ran the corrector w/ this cop on our codebase, using the explicit style. It made one correction which broke factorybot.

I wrote a test that reproduced the behavior below.

The problem is a nested factory that looks like factory :active_article, traits: [:approved, :active] and:

  1. It gets identified as an error (should it be?)
  2. It gets corrected to association :factory, :active_article, traits: [:active, :approved] which breaks the factory

The interesting thing is if I just add a do;end block to my :active_article factory, it ignores the error. I have a draft PR I'm going to push up shortly.

    context 'when implicit association has factory and traits' do
      it 'registers and corrects an offense' do
        expect_no_offenses(<<~RUBY)
          factory :article do
            traits :approved do
              approved { true }
            end

            traits :active do
              active { true }
            end

            factory :active_article, traits: [:approved, :active]
          end
        RUBY
      end
    end
@pirj
Copy link
Member

pirj commented Apr 24, 2024

Thanks for reporting. This looks like a bug, and needs to be fixed if so.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants