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

Cop idea: redundant FactoryBot enum traits #10

Open
pirj opened this issue Nov 2, 2020 · 0 comments
Open

Cop idea: redundant FactoryBot enum traits #10

pirj opened this issue Nov 2, 2020 · 0 comments
Labels

Comments

@pirj
Copy link
Member

pirj commented Nov 2, 2020

FactoryBot has an enum traits feature that given a model:

class Task < ActiveRecord::Base
  enum status: {queued: 0, started: 1, finished: 2}
end

makes the following definitions redundant:

FactoryBot.define do
  factory :task do
    trait :queued do
      status { :queued }
    end

It's near impossible to detect using static analysis, however, I've seen this defined as:

status { Model.status[:queued] }

which is equivalent to the above (just translates a symbol to its DB-level numeric representation explicitly rather than relying on ORM to do that). Those cases are detectable.

NOTE: Enum traits appeared in FactoryBot 6.1, so probably we'll need to introduce version configuration a-la TargetFactoryBotVersion (see rubocop-rails for an example).

@ydah ydah transferred this issue from rubocop/rubocop-rspec May 6, 2023
@ydah ydah added the cop label May 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants